Partager via


DESCENDING( ) Function

Returns a logical value that indicates whether an index tag was created with the DESCENDING keyword or whether the DESCENDING keyword was included in USE, SET INDEX, or SET ORDER.

DESCENDING([CDXFileName[, nIndexNumber [, nWorkArea | cTableAlias]]])

Return Values

Logical

Parameters

  • CDXFileName
    Specifies the name of a compound index file with CDXFileName. The compound index file you specify can be the structural compound index file automatically opened with the table or an independent compound index file.

  • nIndexNumber
    Specifies which index tag or index file DESCENDING( ) tests. nIndexNumber is typically an integer that starts at 1 and is increased by 1 to return additional values for each index tag.

    If nIndexNumber is 1, a value for the master single-entry .idx index file or master index tag (if one is present) is returned.

    As nIndexNumber increases, values for each tag in the structural compound index (if one is present) are returned. The values are returned for the tags in the order in which the tags were created in the structural compound index.

    After values for all the tags in the structural compound index are returned, values for each tag in any open independent compound indexes are then returned. The values are returned from the tags in the order in which the tags are created in the independent compound indexes.

    The empty string is returned if nIndexNumber is greater than the total number of open, single-entry .idx files and structural compound and independent compound index tags.

  • nWorkArea | cTableAlias
    Returns values for index files or tags open in a work area other than the current work area. nWorkArea specifies the work area number and cTableAlias specifies the table alias.

    If no table has the alias you specify, Visual FoxPro generates an error message.

Remarks

You can order records in a table in descending order in two ways:

  • You can include the DESCENDING keyword in the INDEX command to create a descending order index tag in a compound .cdx.
  • You can include the DESCENDING keyword in USE, SET INDEX or SET ORDER to specify a descending order for the master index tag or the master single-entry index (.idx) file.

DESCENDING( ) can determine if an index tag was created in descending order. DESCENDING( ) returns true (.T.) if the index tag you specify was created with the DESCENDING keyword.

DESCENDING( ) can also determine if the master index tag or master index file is in descending order. DESCENDING( ) returns true (.T.) if the DESCENDING keyword was included in USE, SET INDEX, or SET ORDER for the master index tag or a single-entry index (.idx) file you specify.

If you don't include any of the optional arguments, DESCENDING( ) returns a value for the master index tag or master index file. If you don't include any of the optional arguments and a master index tag or .idx file isn't in effect (for example, you've issued SET ORDER TO to place the table in physical record order), DESCENDING( ) returns false (.F.).

Example

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

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

FOR nCount = 1 TO 254
   IF !EMPTY(TAG(nCount))  && Checks for tags in the index
   ? TAG(nCount) + ' Descending? ' && Display tag name
   ?? DESCENDING(nCount)  && Display descending status
   ELSE
      EXIT  && Exit the loop when no more tags are found
   ENDIF
ENDFOR

See Also

INDEX | SET INDEX | SET ORDER | USE