Command SET SOFTSEEK Foundation

Sets whether searches with the command SEEK will be "relative".

Syntax
SET SOFTSEEK on | OFF | <lToggle>
Scope
thread-local, current work space
Parameters
<lToggle>
<lToggle> is a logical expression which must appear in parentheses. Instead of a logical expression, the option ON can be specified for the value .T. (true) or OFF for the value .F. (false). When .T. or ON is specified, a relative search is performed. That means that the record pointer is not positioned after the last record (Eof()) when a search fails, but on the record which has the next index expression value higher than the search expression.
Description

The command SET SOFTSEEK determines where the record pointer is positioned after a failed SEEK operation.

When SET SOFTSEEK is set to ON, the record pointer is positioned after a failed search to the next record whose index value is greater than that of the search value. Filtered records are ignored. If a record exists with a value greater than the search value, the record pointer remains on this record. In this case, the function Eof() and Found() both return the value .F. (false). If no record with a greater value is found, the record pointer points to the "Phantom" record and Eof() returns .T. (true). Regardless of the setting of SET SOFTSEEK, the function Found() only returns .T. (true) when the search value is found.

With SET SOFTSEEK OFF, the record is always positioned at the end of the file after an unsuccessful search and Eof() returns the value .T. (true).

Examples
SET SOFTSEEK
// In the example, the UDF SeekLast() finds the last 
// record corresponding to a specific search 
// expression. SEEK always positions the record pointer 
// on the first record found. Using a "relative" 
// search (SOFTSEEK ON), SeekLast() finds the last data 
// record matching the search value. The function assumes 
// that the search value is in the form of a character 
// string. 

FUNCTION SeekLast( cString ) 
   LOCAL cIndexKey, cIndexVal, nLen 

   cIndexKey  := IndexKey(0) 
   IF Empty( cIndexKey )         // no active index 
      RETURN .F.                 // *** RETURN  *** 
   ENDIF 

   nLen := Len( cString ) 
   SET SOFTSEEK ON               // SOFTSEEK ON 

   ** Raise last Chr() by 1 for SOFTSEEK 
   SEEK Left(cString,nLen-1) + Chr(Asc(Right(cString,1)) + 1) 

   SET SOFTSEEK OFF              // SOFTSEEK OFF 

   SKIP -1                       // skip back 1 
                                 // determine value of the index key 
   IF ( cString == Left(&(cIndexKey),nLen) ) 
      RETURN .T.                 // it matches: Found! 
   ENDIF 

   SKIP                          // If Eof() was == .T. 

RETURN .F. 
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.