Command SEEK Foundation

Positions the record pointer based on the value of an index expression.

Syntax
SEEK [LAST] <Expression> ;
     ORDER [TAG] <cTagName>|<nIndex> ;
     [IN <nWorkArea> | <cAlias> ] ;
     [SOFTSEEK]
Parameters
LAST
The option LAST seeks the last occurrence of the specified <Expression>. If not specified, the default, seeks the first occurrence.
<Expression>
<Expression> is an expression whose value is searched for in the controlling index. The record pointer (RecNo()) is positioned to the corresponding record after the search.
<cTagName>
<cTagName> is a character string specifying the name within the index file of the index to set as the controlling index. <cTagName> is comparable to the alias name of a work area.
<nIndex>
<nIndex> is a positive integer specifying the ordinal position within a work area of the index to select as the controlling index. The indexes are numbered in the order that they were activated using OrdListAdd() or SET INDEX TO.
IN <nWorkArea>
<nWorkArea> is a positive integer specifying the ordinal number of the work area being selected.
IN <cAlias>
This argument is either a literal alias name or a character expression containing the alias name in parentheses. The alias name indicates the work area whose files are to be closed.
SOFTSEEK
The option SOFTSEEK is optional. If <lSoftSeek> is not specified, the current setting of SET SOFTSEEK ON | OFF is used.
<Expression> is an expression whose value is searched for in the controlling index. The record pointer (RecNo()) is positioned to the corresponding record after the search.
Description

If <Expression> is a character string, the first entry beginning with this string is searched in the index file. The expression SEEK "An", for example, positions the record pointer on the first record whose index key starts with the letters "An".

When the value of <Expression> is not found in the index file, the position of the record pointer depends on the setting of SET SOFTSEEK. Normally SET SOFTSEEK is set to OFF, causing the record pointer to be positioned on the "Phantom" record when <Expression> is not found in the index file (with DBF files, this corresponds to the position LastRec()+1). The function Found() then returns the value .F. and the function Eof() returns the value .T.. If SET SOFTSEEK is set to ON, an "inexact" search is performed and the data record pointer is positioned on the first record whose value is greater than the value of <Expression>. When such a record exists, the function Found() as well as Eof() return the value .F. (false).

SEEK searches for a value in an index file. If no index file is open in the current work area, no search occurs and the record pointer remains unchanged.

The function DbSeek() is the functional equivalent of the command SEEK.

Examples
SEEK
// The example shows the command SEEK and the different 
// behavior caused when SOFTSEEK is ON or OFF. 

PROCEDURE Main 
   USE Customer NEW EXCLUSIVE 
   INDEX ON Upper(LName+FName) TO CustName 
   SET INDEX TO CustName 

   ? LName                          // result: Anderson 
   ? FName                          // result: John 
   ? LastRec()                      // result: 100 

   SET SOFTSEEK OFF 
   GO BOTTOM 

   ** Search value corresponds to the index expression 
   ** (upper case letters) 
   SEEK  "ANDERSON      JOHN" 
   ? RecNo()                        // result: 13 

   ** Search value does not correspond to the index expression 
   SEEK  "Anderson      John" 
   ? RecNo()                        // result: 101 
   ? Found()                        // result: .F. 
   ? Eof()                          // result: .T. 

   SET SOFTSEEK ON                  // turn on "inexact" search 

   ** Search value corresponds to the index expression 
   SEEK  "ANDERSON      JOHN" 
   ? LName                          // result: Anderson 
   ? FName                          // result: John 
   ? Found()                        // result: .T. 
   ? Eof()                          // result: .F. 

   ** Search value does not correspond to the index expression 
   ** The record with the next greatest value is found 
   SEEK  "Anderson      John" 
   ? LName                          // result: Baker 
   ? FName                          // result: Fred 
   ? Found()                        // result: .F. 
   ? Eof()                          // result: .F. 

   CLOSE Customer 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.