FIELDNAME() / FIELD() Return a field name from the current database (.dbf) file ------------------------------------------------------------------------------ Syntax FIELDNAME/FIELD(<nPosition>) --> cFieldName Arguments <nPosition> is the position of a field in the database file structure. Returns FIELDNAME() returns the name of the specified field as a character string. If <nPosition> does not correspond to an existing field in the current database file or if no database file is open in the current work area, FIELDNAME() returns a null string (""). Description FIELDNAME() is a database function that returns a field name using an index to the position of the field name in the database structure. Use it in data-independent applications where the field name is unknown. If information for more than one field is required, use AFIELDS() to create an array of field information or COPY STRUCTURE EXTENDED to create a database of field information. If you need additional database file structure information, use TYPE() and LEN(). To obtain the number of decimal places for a numeric field, use the following expression: LEN(SUBSTR(STR(<idField>), RAT(".", ; STR(<idField>)) + 1)) By default, FIELDNAME() operates on the currently selected work area as shown in the example below. Examples . These examples illustrate FIELDNAME() used with several other functions: USE Sales ? FIELDNAME(1) // Result: BRANCH ? FCOUNT() // Result: 5 ? LEN(FIELDNAME(0)) // Result: 0 ? LEN(FIELDNAME(40)) // Result: 0 . This example uses FIELDNAME() to list the name and type of each field in Customer.dbf: USE Customer NEW FOR nField := 1 TO FCOUNT() ? PADR(FIELDNAME(nField), 10),; VALTYPE(&(FIELDNAME(nField))) NEXT . This example accesses fields in unselected work areas using aliased expressions: USE Sales NEW USE Customer NEW USE Invoices NEW // ? Sales->(FIELDNAME(1)) // Result: SALENUM ? Customer->(FIELDNAME(1)) // Result: CUSTNUM Files Library is CLIPPER.LIB.
See Also: AFIELDS()* COPY STRU EXTE DBSTRUCT() FCOUNT()