Partager via


AFIELDS( ) Function

Retrieves and stores information about the structure of the table in a specified work area, specified by a table alias, or in the currently selected work area in an array and returns the number of fields in the table.

AFIELDS( ArrayName [, nWorkArea | cTableAlias ] )

Parameters

  • ArrayName
    Specifies an array to store information about the table structure.

    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.

  • cTableAlias
    Specifies a table alias.

    If you omit nWorkArea and cTableAlias, AFIELDS( ) retrieves information for the table in the currently selected work area.

Return Value

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

Y = Currency

D = Date

T = DateTime

B = Double

F = Float

G = General

I = Integer

L = Logical

M = Memo

N = Numeric

Q = Varbinary

V = Varchar and Varchar (Binary)

W = Blob

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

Concepts

Autoincrementing Field Values in Tables

Reference

ADEL( ) Function

ADIR( ) Function

AELEMENT( ) Function

AINS( ) Function

ALEN( ) Function

ALTER TABLE - SQL Command

ASCAN( ) Function

ASORT( ) Function

ASUBSCRIPT( ) Function

COPY STRUCTURE EXTENDED Command

CREATE Command

CREATE TABLE - SQL Command

DIMENSION Command

Visual FoxPro Data and Field Types

Other Resources

Functions

Language Reference (Visual FoxPro)