Condividi tramite


SEEK( ) Function

Searches an indexed table for the first occurrence of a record whose index key matches a specified expression. Returns a logical value indicating if the search was successful.

SEEK(eExpression [, nWorkArea | cTableAlias
   [, nIndexNumber | cIDXIndexFileName | cTagName]])

Return Values

Logical

Parameters

  • eExpression
    Specifies the index key expression for which you want SEEK( ) to search.

  • nWorkArea
    Specifies the work area number of the table that is searched for the index key.

  • cTableAlias
    Specifies the alias of the table that is searched.

    If you omit nWorkArea and cTableAlias, the table in the currently selected work area is searched.

  • nIndexNumber
    Specifies the number of the index file or tag that is used to search for the index key. nIndexNumber refers to the index files as they are listed in USE or SET INDEX. Open .idx files are numbered first in the order in which they appear in USE or SET INDEX. Tags in the structural .cdx file (if one exists) are then numbered in the order in which they were created. Finally, tags in any open independent .cdx files are numbered in the order in which they were created. For more information about index numbering, see SET ORDER.

  • cIDXIndexFileName
    Specifies an .idx file that is used to search for the index key.

  • cTagName
    Specifies a tag of a .cdx file that is used to search for the index key. The tag name can be from a structural .cdx file or any open independent .cdx file.

    Note   The .idx file takes precedence if duplicate .idx file and tag names exist.

Remarks

You can use SEEK( ) on a table with an index order set, or if an index order is not set on the table, set the controlling index with the 3rd parameter, nIndexNumber, cIDXIndexFileName, or cTagName. The match must be exact unless SET EXACT is set to OFF.

If a match is found, SEEK( ) returns true (.T.), and the record pointer moves to the matching record. If no match is found, SEEK( ) returns false (.F.) and the record pointer moves to the end of the file. Issuing SEEK( ) is equivalent to issuing SEEK and FOUND( ) in succession.

If you omit the nIndexNumber, IDXIndexFileName, and cTagName arguments, SEEK( ) uses the master controlling index or index tag to search for the index key.

Example

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer ORDER cust_id  && Opens Customer table
? SEEK('CHOPS')  && Returns .T., record found

See Also

EOF( ) | FOUND( ) | INDEXSEEK( ) | LOCATE | SEEK | SET ORDER