Function FCount() Foundation
Determines the number of fields in the DBF file open in a work area.
FCount() --> nFieldCount
FCount() returns an integer numeric value. This is the number of fields in a DBF file open in a work area. When no DBF file is open, zero is returned.
The file function FCount() determines the number of fields in a DBF file in a work area. When the function is called without the alias operator, it returns the number of fields in the current work area. FCount() frequently is used to program generic functions or procedures independent of specific database files or fields.
// The example shows a user-defined function which
// copies the values from all fields of the current
// data record into an array.
FUNCTION RecordData()
LOCAL n, aData := Array( FCount() )
FOR n:=1 TO FCount()
aData[ n ] := FieldGet(n)
NEXT
RETURN aData
// The example shows a user-defined function which fills
// an array with the empty values for a data record.
FUNCTION EmptyRecordData()
LOCAL n, aData := Array( FCount() )
LOCAL nRecno := RecNo()
DbGoBottom() // copy values from the
DbSkip() // "ghost-record" into an
FOR n:=1 TO FCount() // array
aData[ n ] := FieldGet(n)
NEXT
DbGoto( nRecno ) // go back to previous data record
RETURN aData
// The example shows a generic input function based on
// FCount(). Get fields are displayed on the screen for
// each field in the DBF file. The number of fields is
// limited by the size of the screen.
PROCEDURE Main
USE Address NEW
EditRecord()
USE
RETURN
PROCEDURE EditRecord()
LOCAL n, cField, cScreen
LOCAL nRow:=0, nCol:=0, nMaxCol:=0
cScreen := SaveScreen() // save screen
CLS
FOR n := 1 TO FCount() // create GETs for each
IF Type( FieldName(n) ) <> "M" // field except Memo field
cField := FieldName(n) // get field name
// display field name
// macro expanding
@ nRow, nCol SAY PadR(cField,10)+":" GET &cField
nMaxCol := Max( nMaxCol, Col() )
nRow ++ // determine whether
// screen is full
IF nRow >= MaxRow()
IF nMaxCol >= MaxCol()
EXIT
ENDIF
nRow := 0
nCol += nMaxCol
ENDIF
ENDIF
NEXT
READ // edit fields
RestScreen(,,,,cScreen) // restore screen
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.