CDX( ) Function

Returns the names of the open compound index (.cdx) file that has the specified index position number.

CDX(nIndexNumber [, nWorkArea | cTableAlias])

Parameters

  • nIndexNumber
    The following apply to a table with a structural compound index and one or more compound indexes:

    nIndexNumber

    Description

    1

    Returns the name of the structural index file (which is always the same as the name of the table).

    2

    Returns the first compound index file name specified in the INDEX clause of USE or in SET INDEX.

    3

    Returns the second compound index file name, if any, and so on.

    Greater than the number of open .cdx files

    Returns the empty string.

    The following apply to a table with no structural compound index and one or more compound indexes:

    nIndexNumber

    Description

    1

    Returns the first compound index file name specified in the INDEX clause of USE or in SET INDEX.

    2

    Returns the second compound index file name, if any, and so on.

    Greater than the number of open .cdx files

    Returns the empty string.

  • nWorkArea
    Specifies the work area number of a table whose open compound index file names you want CDX( ) to return.

  • cTableAlias
    Specifies the alias of a table whose open compound index file names you want CDX( ) to return.

    If you omit nWorkArea and cTableAlias, names of compound index files are returned for the table in the currently selected work area.

Return Value

Character

Remarks

The CDX( ) function is identical to the MDX( ) function.

A .cdx (compound) index consists of one physical file containing many index tags. Each index tag is an index order reference for the associated table.

There are two types of .cdx files: standard compound index (.cdx) and structural .cdx. A standard compound index (.cdx) may have a different name from its associated table and can reside in a different directory from its associated table. A table can have multiple compound index files. You open a compound index with the INDEX clause of USE or with SET INDEX.

A structural .cdx must have the same name as its associated table and reside in the same directory. A table can have only one structural index file. Structural .cdx files are automatically opened and updated when the associated table is opened with USE.

CDX( ) ignores any .idx (Microsoft FoxBASE+ and FoxPro 1.0 compatible index) files specified in USE or SET INDEX.

Use TAG( ) to return individual tag names contained in a .cdx, and NDX( ) to return the name of open .idx files.

When SET FULLPATH is ON, CDX( ) returns the path and name of the .cdx. When SET FULLPATH is OFF, CDX( ) returns the drive and name of the .cdx.

Example

The following example opens the customer table in the testdata database. FOR ... ENDFOR is used to create a loop in which the name of each structural index is displayed.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'data\testdata')
USE customer     && Open customer table

CLEAR
FOR nCount = 1 TO TAGCOUNT( )
   IF !EMPTY(TAG(nCount))  && Checks for tags in the index
   ? CDX(nCount)     && Display structural index names
   ELSE
      EXIT  && Exit the loop when no more tags are found
   ENDIF
ENDFOR

See Also

Reference

INDEX Command

MDX( ) Function

NDX( ) Function

SET FULLPATH Command

SET INDEX Command

SYS(14) - Index Expression

SYS(21) - Controlling Index Number

SYS(22) - Controlling Tag or Index Name

SYS(2021) - Filtered Index Expression

TAG( ) Function

USE Command

Other Resources

Functions

Language Reference (Visual FoxPro)