Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

TAGCOUNT(), TAGNO()

He telleth the number of the stars; he calleth them all by their names.
The Book of Psalms 147:4

This pair of functions was added to FoxPro 2.6 for compatibility with dBase. Despite the short shrift they’re given in the documentation, they’re both fairly useful. TAGCOUNT() tells you the number of tags and stand-alone indexes open for a table, while TAGNO() identifies the position of a tag or index in the list of open indexes.

Usage

nTotalTags = TAGCOUNT( [ cIndexFile [, nWorkArea | cAlias ] ] )

Parameter

Value

Meaning

cIndexFile

Character

Name of the CDX file for which to return a tag count.

Omitted or Empty

Return the total open tag count for the table.

nWorkArea

Numeric

Return information about the table open in work area nWorkArea.

Omitted

If cAlias is also omitted, return information about the table open in the current work area.

cAlias

Character

Return information about the table open as cAlias.

Omitted

If nWorkArea is also omitted, return information about the table open in the current work area.

TAGCOUNT() tells you either how many tags are in a specified index file or the total number of tags and stand-alone indexes open for a table. Despite its documentation, you can pass the name of a stand-alone index file (IDX) for cIndexFile. One use for this capability is to see whether a particular index file is open. If so, TAGCOUNT() returns 1; if the index isn’t open or doesn’t exist, TAGCOUNT() returns 0.

There's a secret to making TAGCOUNT() useful in work areas other than the current work area. The order of parameters makes it seem that you have to inquire about a particular index file in another work area, but passing the empty string for cIndexFile causes the function to return all tag information.

Example

USE Employee    && TasTrade employee table
? TAGCOUNT()    && Returns 3
SELECT 0        && move to another work area
? TAGCOUNT("","Employee")          && Returns 3
? TAGCOUNT("Employee","Employee")  && Returns 3

Usage

nTagNumber = TAGNO( [ cIndexName [, cIndexFile
                    [, nWorkArea | cAlias ] ] ] )

Parameter

Value

Meaning

cIndexName

Character

Name of the stand-alone index or tag whose position is to be returned.

Omitted

Return the position of the current master index.

cIndexFile

Character

Name of the CDX file about which to return information.

Omitted

Return the position of the current master index.

nWorkArea

Numeric

Return information about the table open in work area nWorkArea.

Omitted

If cAlias is also omitted, return information about the table open in the current work area.

cAlias

Character

Return information about the table open as cAlias.

Omitted

If nWorkArea is also omitted, return information about the table open in the current work area.

The tags and stand-alone indexes open at any time have position numbers assigned to them (based on the order in which they were opened—for more on these, see CANDIDATE()). Many of the index information functions (for example, TAG() and KEY()) accept these position numbers to indicate which tag or index you want information about. TAGNO() takes a tag or index name and tells you its current index number.

As with TAGCOUNT(), you can pass the name of a stand-alone index for cIndexFile, but we really can’t see any reason you’d want to, since you have to pass the same name for cIndexName.

Both TAGCOUNT() and TAGNO() simply return 0 if the named index or file doesn’t exist.

Example

USE Employee
? TAGNO("Last_Name")  && Returns 2
? TAGNO("Group_Id")   && Returns 1
SELECT 0              && Go to another work area
? TAGNO("Last_Name","","Employee")  && Returns 2

See Also

Candidate(), Index, Key(), Tag()