AFIELDS( ) Function
Places information about the structure of the current table into an array and returns the number of fields in the table.
AFIELDS(ArrayName [, nWorkArea | cTableAlias])
Return Values
Numeric
Parameters
ArrayName
Specifies an array into which information about the table structure is placed. If the array you include in AFIELDS( ) doesn't exist, Visual FoxPro automatically creates it. If the array exists and isn't large enough to contain all the information returned by AFIELDS( ), the size of the array is automatically increased to accommodate the information.nWorkArea
Specifies the work area of the table for which structure information is placed into an array.cTableAlias
Specifies the alias of the table for which structure information is placed into an array.If you omit nWorkArea and cTableAlias, structure information is placed in an array for the table in the currently selected work area.
The following table describes the content of each column in the first row of the array and the data type of the information stored in each column. Values for table-specific properties in columns 10 through 16 will only appear in the first row of the array. One row is created for each field in the table.
Column number Field info Data type 1 Field name Character 2 Field type:C = CharacterD = DateL = LogicalM = MemoN = NumericF = FloatI = IntegerB = DoubleY = CurrencyT = DateTimeG = General Character 3 Field width Numeric 4 Decimal places Numeric 5 Null values allowed Logical 6 Code page translation not allowed Logical 7 Field validation expression Character 8 Field validation text Character 9 Field default value Character 10 Table validation expression Character 11 Table validation text Character 12 Long table name Character 13 Insert trigger expression Character 14 Update trigger expression Character 15 Delete trigger expression Character 16 Table comment Character
Remarks
AFIELDS( ) returns the number of fields in the table. The array contains 16 columns and the same number of rows as fields in the table.
You can use COPY STRUCTURE EXTENDED to place similar information into a table instead of an array.
Example
The following example creates an array named gaMyArray
containing information about the fields in the customer
table. The names of the fields are displayed.
CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE Customer && Open customer table
gnFieldcount = AFIELDS(gaMyArray) && Create array
CLEAR
FOR nCount = 1 TO gnFieldcount
? gaMyArray(nCount,1) && Display field names
ENDFOR
See Also
ADEL( ) | ADIR( ) | AELEMENT( ) | AINS( ) | ALEN( ) | ALTER TABLE – SQL | ASCAN( ) | ASORT( ) | ASUBSCRIPT( ) | COPY STRUCTURE EXTENDED | CREATE | CREATE TABLE | DIMENSION