JavaScript Editor js editor     Web development 

Main Page

Returns the name of a field, referenced by number, in a table.

FIELD(nFieldNumber | cFieldName [, nWorkArea | cTableAlias [, nFlags]])



Specifies the field number. If nFieldNumber is 1, the name of the first field in the table is returned; if nFieldNumber is 2, the name of the second field is returned, and so on. The empty string is returned if nFieldNumber is greater than the number of fields. Field names are returned in upper case.

Specifies the name of a field. This is used primarily to retrieve the actual field caption as stored in a database container (DBC) when used with the nFlags parameter. If the field caption is an expression (=), the expression is evaluated. Otherwise, the actual string literal is returned. If the expression cannot be evaluated at run time, an error is raised, and the actual field name is returned.

Specifies the work area of the table for which FIELD(В ) returns field names. FIELD(В ) returns the empty string if a table is not open in the work area you specify.

Specifies the alias of the table for which FIELD(В ) returns field names. Visual FoxPro generates an error message if you specify a table alias that does not exist.

Specifies whether the actual field name or field caption is returned.

nFlags Value description


Return actual field name.

FIELD(В ) preserves the case of the returned field name, as long as the table is stored in a DBC.


Return field caption. If the field caption is an expression, return its evaluated value.

Return Value

Character data type. If you omit the optional arguments, FIELD(В ) returns the names of the fields in the table open in the currently selected work area.


You can use the SELECT(В ) function to determine the current work area for nWorkArea. You can use the ALIAS( ) function to determine the alias of the table in the current work area for cTableAlias. For more information, see SELECT(В ) Function and ALIAS(В ) Function.


В Copy Code
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer  && Opens Customer table

FOR gnCount = 1 TO FCOUNT( )  && Loop for number of fields
   ? FIELD(gnCount)  && Display each field
? 'Number of fields: ' + ALLTRIM(STR(gnCount -1))

See Also

JavaScript Editor js editor     Web development