Return a field name from the current database (.dbf) file

     FIELDNAME/FIELD(<nPosition>) --> cFieldName


     <nPosition> is the position of a field in the database file


     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 ("").


     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.


     .  These examples illustrate FIELDNAME() used with several other

        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),;

     .  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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.