Click or drag to resize

FieldName Function (UInt32, Usual)

Return the name of a field as a string.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.4a
Syntax
 FUNCTION FieldName(
	dwFieldPos AS DWORD,
	uArea AS USUAL
) AS STRING
View Source

Parameters

dwFieldPos
Type: UInt32
The position of the field in the database file structure.
uArea
Type: Usual
Specifies the work area name or number for a table from which the value must be retrieved.

Return Value

Type: String
The name of the specified field as a string.
If <dwFieldPos> does not correspond to an existing field in the database file or if no database file is open, FieldName() returns a NULL_STRING.
Remarks
FieldName() 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 DBStruct(). If you need additional database file structure information, use Type() and Len().
For example, to obtain the number of decimal places for a numeric field, use the following expression:
X#
1Len(Substr(Str(<idField>), RAt(".", Str(<idField>)) + 1))
By default, this function operates on the currently selected work area.   It can be made to operate on an unselected work area by specifying it within an aliased expression or by calling the that accepts a workarea parameter (a workarea number or alias ).
Examples
These examples illustrate FieldName() used with several other functions:
X#
1USE sales
2QOut(FIELDNAME(1))                // Result: BRANCH
3QOut(FCount())                    // Result: 5
4QOut(LEN(FIELDNAME(0)))            // Result: 0
5QOut(LEN(FIELDNAME(40)))            // Result: 0
This example uses FieldName() to list the name and type of each field in CUSTOMER.DBF:
X#
1USE customer NEW
2FOR nField := 1 UPTO FCount()
3    ? FIELDNAME(nField), DBFieldInfo(DBS_TYPE, nField)
4NEXT
This example accesses fields in unselected work areas using aliased expressions:
X#
1USE sales NEW
2USE customer NEW
3USE invoices NEW
4QOut(Sales->FIELDNAME(1))        // Result: SaleNum
5QOut(Customer->FIELDNAME(1))        // Result: CustNum
See Also