Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - locate search database for record matching a condition http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 locate              Search database for record matching a condition
------------------------------------------------------------------------------
 Syntax
   [!sAlias] locate [scope] for lExp [while lExp]

 Arguments
   sAlias is the database to operate on.
   scope specifies a portion of the source database.
   lExp is a logical expression.

 Description
   The locate command positions the record pointer to the first record
   matching the search criteria within an alias. The search criteria are
   given by the expression specified with the for clause.

   If a match is found, then found() returns .t.. The found flag is not
   associated with a specific database. It is only associated with the
   last locate or seek command.

   The default scope for locate is all. To search for the next record
   matching the search criteria, use the continue command.

 Example
   #define EXAMPLE_DATABASE
   #include example.hdr

   vardef static
      char cFirst
      char cLast
   enddef
   
   proc GetQuery static
   accept "Query first name: " to cFirst
   accept "Query last  name: " to cLast
   // establish the filter criteria
   set filter to
   if .not. isempty( cFirst )
      set filter to sTest->firstname = cFirst additive
   endif
   if .not. isempty( cLast )
      set filter to sTest->lastname = cLast additive
   endif
   endproc
   
   proc Test_locate
   open sTest
   !sTest locate while ( dtoc( sTest->due ) == dtoc( today() ) ) ;
      for ( sTest->balance < 0 )
   do while found()
     ? recno(), sTest->firstname, sTest->lastname
     !sTest continue
   enddo
   ?
   go top
   do while .t.              // do query by example using multiple filters
      GetQuery()
      if cFirst == "quit"
         exit
      endif
      !sTest locate
      do while found()
         ? sTest->firstname, sTest->lastname
         !sTest continue
      enddo
   enddo
   endproc

   proc main
   Test_locate()
   endproc

See Also: Database command scope table continue find seek

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson