Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scan endscan break
Message
From
17/12/2007 21:28:37
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01276291
Message ID:
01276392
Views:
25
>I another database language I use there is a powerful FOR loop...
>
>
>for each customer where customer.country='USA'
>    break by customer.state no-lock:
>
>    if first-of(customer.state) then do:
>        /* do something with first record */
>    end.
>
>    /* do something with records */
>
>    if last-of(customer.state) then do:
>        /* do something with last record  */
>    end.
>
>end.
>
>
>Scan endscan sort of does this but I cannot break. Can VFP do something like this?

While there's no simple function that will return last-of(), in VFP you can always get your data into a cursor, in whichever order you want, and then do something at the first record (before the loop) and then at the last record. If there are multiple records for customer.state, then have two cursors...
select ... into crsCustomerRecords order by state,...

select distinct state from crsCustomerRecords into crsStates order by 1

select crsStates
*-- first state, we're on top.
scan
   select crsCustomerRecords 
   scan while state=crsStates.state
      * do something while in the middle
   endscan
   if eof("crsStates")
*-- last state
   endif
endscan

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform