Compartir a través de


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 ] )

Parameters

  • ArrayName
    Specifies an array into which information about the table structure is placed.

    If the array you specify does not exist, Visual FoxPro automatically creates it. If the array exists and is not 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.

Return Values

Numeric data type. AFIELDS( ) returns the number of fields in the table. The array contains 18 columns and has the same number of rows as fields in the table.

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 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 = Character

D = Date

L = Logical

M = Memo

N = Numeric

F = Float

I = Integer

B = Double

Y = Currency

T = DateTime

G = 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
17 NextValue for autoincrementing Numeric
18 Step for autoincrementing Numeric

Remarks

If the fields in the table use autoincrementing, the Step value is greater than 0.

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, which contains 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( ) | Autoincrementing Field Values in Tables | COPY STRUCTURE EXTENDED | CREATE | CREATE TABLE | DIMENSION