Show/Hide Toolbars

XSharp

NoteThis command is defined in a header file and will be preprocessed by the X# preprocessor to a function call. If you disable the standard header (-nostddefs) files then this command will not be available. If you tell the compiler to use a different standard header file (-stddef ) then this command may also be not available

Purpose

Search for the first record in the current work area that matches the specified condition and scope.

Syntax

LOCATE [<Scope>] FOR <lCondition> [WHILE <lCondition>]

Arguments

<Scope>The portion of the current database file to process.  The default is all visible records. Scope is one or more clauses of:
[NEXT <NEXT>]        Optionally specifies the number of records to process starting
               with the first record of the source file.
[RECORD <rec>]        An optional record ID If specified, the processing begins
               with this data record in the source file.
[<rest:REST>]        The option REST specifies whether records are sequentially
               searched only from the current up to the last record.
               If a condition is specified, the option ALL is the default value.
[ALL]                The option ALL specifies that all records from the source file are imported.
               This is the default setting.

 

WHILE <lCondition>A condition that each visible record within the scope must meet, starting with the current record.  As soon as the while condition fails, the process terminates.  If no <Scope> is specified, having a while condition changes the default scope to the rest of the visible records in the file.

 

FOR <lCondition>A condition that each visible record within the scope must meet in order to be processed.  If a record does not meet the specified condition, it is ignored and the next visible record is processed.  If no <Scope> or WHILE clause is specified, having a for condition changes the default scope to all visible records.

 

Description

LOCATE evaluates each visible record within the scope using the for condition.  As soon as a record meets the condition, the process terminates, leaving the record pointer on the matching record and setting the Found() flag to TRUE.  If the for condition is FALSE for all records in the scope, the Found() flag is set to FALSE, and the position of the record pointer depends on the scope.

 

Each work area has its own locate condition which remains active until you execute another locate operation (for example, with LOCATE or DBLocate()), reset the locate condition (for example, with VODBSetLocate()), or terminate the application.

Notes

CONTINUE: Once you locate a record and have processed it, you can resume the search from the current record pointer position with CONTINUE (or DBContinue()).  Both the <Scope> and the while condition, however, apply only to the initial locate operation and are not known by subsequent continue operations.  To continue a pending locate with a scope or while condition, use SKIP then LOCATE REST WHILE <lCondition> instead of CONTINUE as shown in the example below.

Examples

These examples show typical LOCATE constructs:

 

USE sales INDEX salesman
LOCATE FOR Branch = "200"
? Found(), EOF(), RECNO()        // Result:  TRUE FALSE 5
LOCATE FOR Branch = "5000"
? Found(), EOF(), RECNO()        // Result:  FALSE TRUE 85

 

The next example shows a LOCATE with a WHILE condition that is continued by using LOCATE REST:

 

SEEK "Bill"
LOCATE FOR Branch = "200" WHILE Salesman = "Bill"
DO WHILE Found()
 ? Branch, Salesman
 SKIP
 LOCATE REST FOR Branch = "200" WHILE ;
                         Salesman = "Bill"
ENDDO

Assembly

XSharp.RT.DLL

See Also

CONTINUE, DbContinue(), DbLocate(), EoF(), Found(), RecNo(), SEEK, DbSetFilter()