Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Scan endscan break
Message
De
17/12/2007 21:28:37
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01276291
Message ID:
01276392
Vues:
22
>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform