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.
CDX()
, MDX()
, NDX()
These functions give you the names of index files. CDX()
and MDX()
are identical. Both return the name of a compound index file; MDX()
is included only for compatibility with dBASE. NDX()
returns the name of a stand-alone index file.
cIndexFile = CDX( nWhichIndex [, nWorkArea | cAlias] )
cIndexFile = MDX( nWhichIndex [, nWorkArea | cAlias] )
cIndexFile = NDX( nWhichIndex [, nWorkArea | cAlias] )
Parameter |
Value |
Meaning |
nWhichIndex |
Numeric |
Determines which open index file has its name returned. |
nWorkArea |
Numeric |
Return index information about the table open in work area nWorkArea. |
Omitted |
If cAlias is also omitted, return index information about the table in the current work area. |
|
cAlias |
Character |
Return index information about the table open with alias cAlias. |
Omitted |
If nWorkArea is also omitted, return index information about the table in the current work area. |
|
cIndexFile |
Character |
The name of the specified index file. |
Empty |
There is no such index file. |
When multiple index files are opened for a table, they’re assigned positions based on the order in which they’re specified. For example, if you:
USE MyTable INDEX AnIndex, AnotherIndex
AnIndex is index 1 and AnotherIndex is index 2. The parameter nWhichIndex is based on this ordering. For CDX()
and MDX()
, a structural index file is always index 1, if it exists. Any CDX files explicitly opened come after the structural index.
We don’t use these functions often, but when we do, it’s usually CDX()
and it’s because some of the other index functions (like TAGNO()
and TAGCOUNT()
) need the name of the index file when you pass them an alias.
These functions have one very friendly behavior. If you pass a value for nWhichIndex larger than the number of index files of that type that are open, they return the empty string. This makes these functions ideal for writing code to find all the open indexes.
* create an array containing all CDX files for current work area
LOCAL cCDX, nCDXCnt
DIMENSION aCDX[1]
aCDX[1]=""
nCDXCnt=1
DO WHILE NOT EMPTY(CDX(nCDXCnt))
DIMENSION aCDX[nCDXCnt]
aCDX[nCDXCnt]=CDX(nCDXCnt)
nCDXCnt=nCDXCnt+1
ENDDO
* get the name of the third open stand-alone index file
* for MyOldTable
? NDX(3, "MyOldTable")
All three functions respect the current setting of SET FULLPATH
. With SET FULLPATH
ON, they return a fully qualified file name; when SET FULLPATH
is OFF, they return only the drive and index name.
As with other functions that let you pass an alias or work area number, we strongly recommend you don’t use work area numbers. Always refer to tables by their aliases.
Index, Key(), Order(), Set FullPath, Set Index, Sys(14), Tag(), TagNo(), TagCount(), Use