SEEK
Searches for the first record in an indexed table whose key fields matches the specified expression or expression list.
Syntax
SEEK <exp> | <exp list>
<exp>
The expression to search for in an index for a DBF table.
<exp list>
One or more expressions, separated by commas, to search for in a simple or composite key index for non-DBF tables.
Description
dBASE Plus can search a table for specific information either by a sequential search of a table or by an indexed search of the table's master index. A sequential search is similar to looking for information in a book by reading the first page, then the second, and so on, until the information is found or all pages have been read. LOCATE uses this method, checking each record until the information is found or the last record has been inspected.
An indexed search is similar to looking up a topic in a book index and turning directly to the appropriate page. Once a table index is created, SEEK can use this index to quickly identify the appropriate record.
SEEK looks for the first match in the index. If a match is found, the record pointer of the associated table is positioned at the record containing the match, and FOUND( ) returns true.
Use SKIP to access other records whose key fields match the index key fields or expression. SKIP advances the record pointer one record; because of the indexed order, other matches immediately follow the first. However, SKIP after SEEK (unlike CONTINUE after LOCATE) doesn't search for a match; it moves the record pointer one record whether or not it finds a match. You can combine SEEK and LOCATE or SEEK and SCAN (both with the WHILE clause) to do a quick indexed search for the first matching record before looking through or processing all the other matches.
The SET NEAR setting determines whether dBASE Plus, after an unsuccessful SEEK, positions the record pointer at the end-of-file or at the record in the indexed table immediately after the position at which the value searched for would have been found. If SET NEAR is OFF (the default) and SEEK is unsuccessful, EOF( ) returns true and FOUND( ) returns false. If SET NEAR is ON and SEEK is unsuccessful, EOF( ) returns false (unless the position at which the sought value would have been found is the last record in the index), and FOUND( ) returns false.
The expression you look for with SEEK must match the key expression or fields of the master index. For example, if the master index key uses UPPER( ), the search expression must also be in uppercase.
For tables that support composite key indexes based on multiple fields, specify a value for each field in the composite key, separated by commas.
When you seek a key expression of type character, the rules established by SET EXACT determine if a match exists. If SET EXACT is OFF (the default) only the beginning characters of the key field need to be used for SEEK to find a match. For example, if SET EXACT is OFF, SEEK "S" will find "Sanders", or whatever the first key value is that starts with "S". If SET EXACT is ON, the expression must be identical to the key field for a match to exist.
SEEK and LOCATE each have their own advantages. SEEK conducts the most rapid searches; however, it requires an indexed table and can search only for values of the key expression.
If the information for which you are searching is in an unindexed table or is not contained in the key fields of an index, you can use LOCATE. LOCATE accepts any logical condition, which can specify any fields in the table in any combination. For large tables, however, a sequential search using LOCATE can be slow. In such cases, you might want to use INDEX to create a new index and then use SEEK or SEEK( ).
The SEEK( ) function works like SEEK followed by FOUND( ), except that SEEK searches in the current work area, while SEEK( ) can search in the current or a specified work area. However, SEEK( ) can only search for a single expression; it does not support composite keys based on multiple fields. SEEK( ) returns true or false depending on whether the search is successful.
OODML
Use the Rowset object’s findKey( ) or findKeyNearest( ) methods.