Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about SCAN 2

Status
Not open for further replies.

monikai

Programmer
Aug 4, 2002
358
PL
Hi,
i didn't send question so long, but now i have discussion with my collegues about scan.
I have some procedures to control the same group of record and i use scan.

proc1
scan

proc2
scan

proc3
scan
.........
they exexuted one by one.
it's good when: scan for, but my collegue propose change it to: scan while. She said that scan go to first record. But then it working not good.
i want change it:

proc1
zm_nr=recno()
scan

proc2
goto zm_nr
scan

proc3
goto zm_nr
scan
.........
but it will be working good?
thanks for your advice and help




Regards from Monika (Warszawa - Poland)
(monikai@yahoo.com)
 
SCAN WHILE is best used when your data is INDEXED or otherwise sorted by the field(s) you want to use to identify the records you want to SCAN, and then used with a SEEK. Given an index it is blazing fast if you only need to process a few records in a large table.

e.g.
seek(lnMyValue) &&assumes index on MyValue
SCAN WHILE MyValue=lnMyValue
*do stuff
ENDSCAN

Brian
 
And don't forget FOR either...

SCAN FOR SomeField = 2 WHILE MyValue=lnMyValue
*do stuff
ENDSCAN
 
very thank for your quick answer. I think like you. But i don't know about while and for together in scan.

Regards from Monika (Warszawa - Poland)
(monikai@yahoo.com)
 
HI Monikai

You are coming after a long time :)

SCAN ... ENDSCAN is intelligent.

IF you
SCAN FOR myField = myValue
ENDSCAN
you can optimize it for rushmore by having the myField match that of an index expression. VFP will take care of rest.

When you use..
SCAN WHILE...
ENDSCAN
one has to be very careful to start the SCAN after making the while condition .t.. Otherwise, the scan will find the WHILE condition .f. and will not do the looping.

Example..
USE mySTates
SCAN FOR mySTateField = "CA"
...
ENDSCAN
This will do the thinkg correcttly every time.

USE myTable
LOCATE FOR myStateField = "CA"
SCAN WHILE mySTateField = "CA"
..
ENDSCAN

will do the same. Now you can see the first LOCATE statement. In this case, if the next record mySTateField is not "CA", but after 5 records it is "CA", you will end up SCAN not finding that. If you set the ORDER of the table to the myStateField, you can get correct answer.

SO I would recommend to use SCAN FOR.. ENDSCAN which will not trap you undexpectedly.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
hi, Ramani
Yes i prefer 'scan for' too, but i have very big file.
I'm glad that you remember me.
Thanks for your answer

Regards from Monika (Warszawa - Poland)
(monikai@yahoo.com)
 
If you have an index on myStateField

This would be the way to go if the file is large since seek is faster than locate:

USE myTable
&&LOCATE FOR myStateField = "CA"
SEEK("CA")
SCAN WHILE mySTateField = "CA"
..
ENDSCAN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top