Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
'SCAN FOR' vs 'LOCATE FOR'
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00301450
Message ID:
00301499
Views:
28
Hi Chris...

As everyone has pointed out, these commands are rushmore optimizable. However, that isn't the real key to the speed. First off, the FOR operator will evaluate ALL records. Instead, it is much faster to use a combination of Seek and Locate.

For example, lets say you wanted to loop through the records where state = "PA". Something like this would be much faster:

Select customers
If Seek("PA","customers","state")
Scan While State = "PA"
*/ Do your stuff
EndScan
Endif

The Locate For command is good to use when an index is not available. Given a large population of records, without an index, you really wont be able to speed things up....

if you have a lot of records, and you have the appropriate index tags available, the above technique will provide the fastest performance since you will only evaluate the records you need to, not the entire table....

HTH...


>Hi everyone
>
>I've been using the 'SCAN FOR' command and the 'LOCATE FOR' command in some of my applications. In terms of speed - does anyone know which is supposed to be faster? They appear to work about the same speed to me...
>
>Regards
>
>Chris Kable
>FuelTrac
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform