Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scan / Endscan and processing logic
Message
From
05/07/2006 10:45:56
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01127322
Message ID:
01133840
Views:
30
This message has been marked as a message which has helped to the initial question of the thread.
>>>>>Ok, finally I've realized, that I can not use scan/endscan and I have to switch to
>>>>>
>>>>>for i=1 to reccount() + 1
>>>>>
>>>>>next
>>>>>
>>>>>Thanks.
>>>>
>>>>Alowing that you missed 'skip' in a hurry, hv to ask ;
>>>>What is the diff ? It comes down to the same any way you turn it.
>>>>Weather u r doing for/skip/next or dowhile/skip/enddo or scan/endscan,
>>>>you are basically going arround the same bush.
>>>>
>>>
>>>You missed the fact, that I'm looping for reccount() + 1. In other words, I do additional cycle for last record and I also made my if statement slightly different
>>>
>>>if not cCarrier_Name == m.lcCarrier_Name or m.lnI = reccount() + 1
>>>   * create file, etc.
>>>endif
>>>
>>>In other words, I needed to create a file for each different client and each different carrier. If I'm using scan/endscan, I have to repeat the code after the scan to create file for the last set of client/carrier. Originally I added a check in scan itself and was surpised, that my eof() or reccount() = recno() didn't work. But then I realized, that my logic dictates one additional loop, that I was able to achieve with for loop.
>>
>>
>>Hi Naomi,
>>
>>You got me little bit confused now ...
>>If you prepared cursor BEFORE this action by having ONE distinct record for each client/carrier then whole thing should be pretty straightforward.
>>.
>>scan
>> ->do your thing
>>endscan
>>.
>>No ifs, no buts, no thens , nothing before and nothing afterwards.
>>
>>
>>If cursor contain GROUPS of records that you hv to process and perform
>>action for each group of records within this cursor, then you need to
>>sort your cursor (order by / or index) - similar to as if you wanted to print ordinary grouped report out of it.
>>
>>So your processing should be embeded in folowing nested scan/endscan construction - typical for grouped processing of records.
>>
>>
>>
>>select curProcess && Order by pk
>>go top
>>scan
>>
>>  lcTrans_pk = curProcess.cTrans_pk &&grouped by PK
>>
>>  *-> Here you do whatever BEFORE group of records is scanned
>>  scan while curProcess.cTrans_pk = lcTrans_pk
>>
>>      *-> do whatever with EACH record of the group
>>
>>  endscan
>>  skip -1 &&<-- Do not ommit this!
>>
>>  *-> Here you do whatever AFTER entire group just passed/before new group
>>  *-> that wld be preparing file / updating related records for you here
>>  =PrepareYourFileAndUpdateRelatedData(lcTrans_pk)
>>
>>endscan
>>
>>
>>Again no ifs,thens,buts recno()s eof()s bof()s etc.
>>
>>Aldough I am sure you are NOT gonna go for this, but rather try to
>>fix your existing code (eh.. we all love our babies...)
>>- have this in mind next time you come across simmilar case :)
>
>This would work as well, but I don't see why 2 scans are better than one loop with if/endif?

Every line of code we write is interpreted by vfp on the fly. Certain lines of code are the equivalent of calling major c++ functionality - not compiled on the fly.
go top
do while not eof
  if condition
    replace field
  endif
  if not eof()
    skip
  endif
enddo
versus
scan for condition
    replace field
versus
replace something for condition
The last should be the fastest because vfp is doing all the work, not your custom code.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform