FCount(), FldCount(), Field(), FSize()

FCOUNT() and FLDCOUNT() return the number of fields in a table. FIELD() returns the name of a specified field in a table. FSIZE() is confused: It is two different functions, depending on the setting of—ugh!—SET COMPATIBLE. Generally speaking, we avoid these commands altogether, and let AFIELDS() give us all the information at once.

Usage

nFieldCount = FCOUNT( [ cAlias | nWorkarea ] )
nFieldCount = FLDCOUNT( [ cAlias | nWorkarea ] )
cFieldName = FIELD( nField, [ cAlias | nWorkarea ] )
* With SET COMPATIBLE OFF:
nFieldSize = FSIZE( cFieldName, [ cAlias | nWorkarea ] )
* With SET COMPATIBLE ON:
nFileSize = FSIZE( cFileName )

Parameter

Value

Meaning

cAlias

Character

The alias of the table about which information is returned.

Omitted

If nWorkarea is also omitted, use current work area.

nWorkarea

Numeric

The number of the work area containing the table about which information is returned.

Omitted

If cAlias is also omitted, use current work area.

nFieldCount

Numeric

Number of fields in the specified table.

nField

Numeric

Number of the field to return, based on physical order of the table.

cFieldName

Character

The field's name.

nFieldSize

Numeric

Size of the field (SET COMPATIBLE OFF).

cFileName

Character

The name of the file.

nFileSize

Numeric

Size of the file (SET COMPATIBLE ON).


FCOUNT() and FLDCOUNT() do not report on hidden, system fields (see "DBF, FPT, CDX, DBC—Hike!"). If you use one of them with FSIZE() to try to calculate the size of a table, you'll come out with the wrong number if any of the fields are nullable. You need to use RECSIZE() or AFIELDS() to test for this, and while you're at it, you can use the return value of AFIELDS() for a better FCOUNT() and the sum of the AFIELDS() size values for a better FSIZE().


FLDCOUNT() is a totally undocumented clone of FCOUNT(), added in FoxPro 2.6 as part of the dBase IV compatibility campaign. We recommend you avoid it, if for no other reason than to take pity on the poor soul who has to maintain your code. After all, it might be you.FIELD() returns the name of the field based on its order within the table. Because fields within a table can be rearranged quite easily, you'll not want to hardcode field-order numbers into your code. Instead, FIELD() could prove valuable in a black-box looping structure where you're scanning for certain field names. However, AFIELDS() provides a lot more information in an easily manipulated array and tends to be the function we prefer to use.FSIZE() is a horror show. Fox Software and Ashton-Tate each went its own way with this function—it's one of the few that is affected by the dreaded SET COMPATIBLE command. If SET COMPATIBLE is OFF or FOXPLUS, FSIZE() returns the field size of the specified field. If FSIZE() is called with SET COMPATIBLE STUPID, er, we mean, ON or DB4, it returns the size of the specified file. Our advice: Leave COMPATIBLE SMART (FoxPlus) and use ADIR() to get file sizes.
Example
SET COMPATIBLE FOXPLUS
USE HOME() + "LABELS"
nFieldSize = FSIZE("Name", "Labels") && returns 24
SET COMPATIBLE DB4
nFileSize = FSIZE(HOME()+"Labels")   && returns 6622
? FCOUNT("LABELS")                   && seven
? FIELD(3, "LABELS")                 && returns "NAME"

See Also

ADir(), AFields(), ALen(), RecSize(), Set Compatible


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .