Get a Jumpstart with our Sample Apps
Results 1 to 3 of 3

Thread: Pack Table global function

  1. #1
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Pack Table global function

    Here is an Alpha 5 pack table global function shown below and attached as a Zip file. It checks for the table in use and conditionally packs.

    Regards,

    Ira J. Perlow
    Computer Systems Design & Associates
    csda@mediaone.net


    function PackTable as N(TableName as C)
    ' Created by Computer Systems Design & Associates
    ' Copyright 2000 Computer Systems Design & Associates, All Rights Reserved
    ' Last Update: June 15, 2000

    ' Purpose: Packs a table if it is available exclusively for packing

    ' Input: TableName = Name of Table to pack

    ' Output: The number of tables packed. Zero indicates nothing was packed

    ' Errors: If TableName is blank, the current table of the active layout
    ' or doesn't exist, then a zero is returned

    ' Typical Usage:
    ' PackTable("Invoices") ' Pack Invoice table if available

    ' Examples:
    ' PackTable("Invoices")

    ' Notes:

    ' Set inital return value
    PackTable=0

    ' Get current table's name
    curtbl=Table.Current().Name_Get()

    'Possible values for Mode are:
    ' 16 (Read only, exclusive)
    ' 18 (Read/write,exclusive),
    ' 64 (Read only, shared)
    ' 66 (Read/write, shared).
    ' Set value here because Alpha 5's constants don't always work
    file_rw_exclusiv=18

    tblnam=trim(TableName)

    ' If table name is not blank, then check
    IF .not.(tblnam=="")

    ' If table name is not current table, then check
    IF .not.(UT(curtbl)==UT(tblnam))
    ' Set error flag initially to 0
    errflag=0

    ' Set error handler
    ON ERROR GOTO Error_handler

    ' Try to open the table exclusively
    tbl=table.open(tblnam,file_rw_exclusiv)

    ' Clear error handling
    ON ERROR GOTO 0

    ' See if error flag has changed
    IF errflag=0
    ' If error flag is still 0, then pack the table

    ' Display table name in the Trace Window
    ' trace.writeln("Repacking "+tblnam)

    :Statusbar.Set_Text("Packing Table "+tblnam)
    tbl.pack()
    :Statusbar.Set_Text("Packing Table "+tblnam+" complete")
    tbl.close()

    ' Set return value
    PackTable=1
    ELSE
    :Statusbar.Set_Text("Unable to Pack Table "+tblnam)
    ui_msg_box("Error",msg,UI_ATTENTION_SYMBOL)
    END IF
    END IF

    END IF

    END

    error_handler:
    err=error_code_get()
    msg=error_text_get(err)
    errflag=1
    RESUME NEXT

    END

    end function


  2. #2
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,207

    Default Re: Pack Table global function

    Recently I needed to copy this script again and discovered a bug:
    Table is opened before error check and if errorflag = 1 the table is not closed. Need to add tbl.close() after the ELSE
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,696

    Default Re: Pack Table global function

    Robin,

    You didn't indicate where you are using the script but there have been additions to xbasic since Ira's contribution. If the table to be packed is the table upon which a form is based and that form contains the button triggering the pack, you can now make use of A5RunXbasicAfterClosingWindows().
    There can be only one.

Similar Threads

  1. global function help, please
    By Bob Arbuthnot in forum Alpha Five Version 6
    Replies: 6
    Last Post: 10-07-2005, 12:11 PM
  2. Global Function Anybody?
    By MoGrace2U in forum Alpha Five Version 4
    Replies: 17
    Last Post: 06-09-2005, 01:51 PM
  3. global function and runtime
    By R.F. Groes in forum Alpha Five Version 5
    Replies: 6
    Last Post: 08-07-2004, 02:20 PM
  4. Function vs Global Script
    By dik_coleman in forum Alpha Five Version 5
    Replies: 2
    Last Post: 07-15-2004, 04:17 PM
  5. global function help urgent
    By deathwatcher in forum Code Archive
    Replies: 1
    Last Post: 12-11-2001, 11:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •