Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper 5.3 . Guide To CA-Clipper - <b>afields()*</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 AFIELDS()*
 Fill arrays with the structure of the current database file
------------------------------------------------------------------------------
 Syntax

     AFIELDS([<aFieldNames>], [<aTypes>],
        [<aWidths>], [<aDecimals>]) --> nFields

 Arguments

     <aFieldNames> is the array to fill with field names.  Each element
     is a character string.

     <aTypes> is the array to fill with the type of fields in
     <aFieldNames>.  Each element is a character string.

     <aWidths> is the array to fill with the widths of fields in
     <aFieldNames>.  Each element is numeric data type.

     <aDecimals> is the array to fill with the number of decimals defined
     for fields in <aFieldNames>.  Each element is numeric data type.  If the
     field type is not numeric, the <aDecimals> element is zero.

 Returns

     AFIELDS() returns the number of fields or the length of the shortest
     array argument, whichever is less.  If no arguments are specified, or if
     there is no file in USE in the current work area, AFIELDS() returns
     zero.

 Description

     AFIELDS() is an array function that fills a series of arrays (structure
     attribute arrays) with the structure of the database file currently
     open, one element in each array per field.  AFIELDS() works like ADIR(),
     filling a series of existing arrays with information.  To use AFIELDS(),
     you must first create the arrays to hold the database structure
     information, each with the same number of elements as the number of
     fields (i.e. FCOUNT()).  Once the structure attribute arrays are
     created, you can then invoke AFIELDS() to fill the structure arrays with
     information about each field.

     By default, AFIELDS() operates on the currently selected work area.  It
     can  operate on an unselected work area if you specify it within an
     aliased expression (see example below).

     AFIELDS() is a compatibility function and therefore is not recommended.
     It is superseded by DBSTRUCT(), which does not require the existence of
     any arrays prior to invocation and returns a multidimensional array
     containing the current database file structure.

 Examples

     .  This example demonstrates how AFIELDS() and ACHOICE() can be
        used together to create a fields picklist:

        USE Sales NEW
        PRIVATE aFieldNames[FCOUNT()]
        AFIELDS(aFieldNames)
        @ 1, 0 TO 10, 10 DOUBLE
        nChoice := ACHOICE(2, 1, 9, 9, aFieldNames)
        @ 12, 0 SAY IF(nChoice != 0, aFieldNames[nChoice],;
                        "None selected")
        RETURN

     .  This example uses AFIELDS() with an aliased expression to fill
        arrays with the structure of Sales.dbf, open in an unselected work
        area:

        LOCAL aFieldNames, aTypes, aWidths, aDecimals
        USE Sales NEW
        USE Customer NEW
        //
        aFieldNames := Sales->(ARRAY(FCOUNT()))
        aTypes := Sales->(ARRAY(FCOUNT()))
        aWidths := Sales->(ARRAY(FCOUNT()))
        aDecimals := Sales->(ARRAY(FCOUNT()))
        //
        Sales->(AFIELDS(aFieldNames, aTypes, ;
                 aWidths, aDecimals))

 Files   Library is EXTEND.LIB.


See Also: ACHOICE() ADIR()* AEVAL() ASCAN() DBCREATE()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson