Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sums
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: Sums
Divers
Thread ID:
00761911
Message ID:
00761952
Vues:
27
I didn't test, buts its an idea using ADEL
* Rolling Six Fields
dime myAr[6]                   && This array will contain last 6 fields
select myfile                  && Er, your file
lnRecCtr=1                     && Pointer in case deleted or indexed
go top                         && Top of file
do while !eof and lnRecCtr<7   && Loop through 6, land on 7
myAr[lnRecCtr]=nFieldOne       && Stash the field to myAr ele,emt
lnRecCtr=lnRecCtr+1            && Bump the pointer
skip                           && Bump the record
enddo                          && Done with first 6 fields, now on 7

* At # 7
do while !eof()                && Continue to bottom
repl nFieldTwo with myAr[1]+myAr[2]+....+myAr[6] && Field being summed to
ADEL(myAr,1)                   && Delete first element of array
dime myAr[6]                   && redim array to 6
myAr[6]=nFieldOne              && Add current field to end of array
skip                           && Next record
enddo                          && ANd over, and over, and over
>Suppose I have a table with 1000 records and 2 numeric fields (I call them columns belo).
>The first column has random data in it, integers no bigger than 100, no smaller than
>0. Starting with the 7th record record, I want to replace each record in second column
>with the sum of the 6 preceeding records, from column 1.
>
>I could do this with a do while loop, of course, but is there a quick way to do this
>using a repl all command, one that knows how to take the sum of the proceeding 6 records
>in column 1?
>Thanks
>Steve
Imagination is more important than knowledge
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform