Searches a table for the first occurrence of a record whose index key matches a general expression, then moves the record pointer to the matching record.
|Visual FoxPro does not support seek operations for binary indexes.|
SEEK eExpression [ORDER nIndexNumber | IDXIndexFileName | [TAG] TagName [OF CDXFileName] [ASCENDING | DESCENDING]] [IN nWorkArea | cTableAlias]
- Specifies the index key for which SEEK searches. eExpression can be null.
- ORDER 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. See SET ORDER Command for more information about index numbering.
- ORDER IDXIndexFileName
- Specifies an .idx file that is used to search for the index key.
- ORDER [TAG] TagName [OF CDXFileName]
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.
If identical tag names exist in open independent .cdx files, use OF CDXFileName to specify the .cdx file containing the tag.
Note: The .idx file takes precedence if duplicate .idx file and tag names exist.
- Specifies that the table is searched in ascending order.
- Specifies that the table is searched in descending order.
- IN nWorkArea
- Specifies the work area number of the table that is searched.
- IN cTableAlias
- Specifies the alias of the table that is searched. If you omit IN nWorkArea and IN cTableAlias, the table in the currently selected work area is searched.
You can use SEEK only with indexed tables, and you can search only on the index key. The match must be exact unless SET EXACT is set to OFF.
If SEEK finds a record with a matching index key, RECNO(В ) returns the record number of the matching record, FOUND(В ) returns true (.T.), and EOF(В ) returns false (.F.).
If a matching key isn't found, RECNO(В ) returns the number of records in the table plus 1, FOUND(В ) returns false (.F.), and EOF(В ) returns true (.T.).
If SET NEAR is on, the record pointer is positioned immediately after the record with the closest index key. If SET NEAR is off, the record pointer is positioned at the end of the file. In either case, RECNO() returns the record number of the closest record.
In the following example, the Customer table is opened and indexed on the Company field. SEEK is used to find the index key expression that matches the value contained in the variable
CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') USE customer ORDER company && Opens Customer table SET EXACT OFF STORE 'B' TO gcSeekVal SEEK gcSeekVal IF FOUND( ) DISPLAY FIELDS company, contact ENDIF