Information générale
Catégorie:
Codage, syntaxe et commandes
>>Does someone know why the 2 following methods to calculate MyTotal don't give me the same value.
>>
>>I think I mist something with buffering but I'm not
>>100% sure.
>
>I tested your code last night. They are returning the same result. Also, the forms does not contain buffering, so buffering does not apply ehre. The REPLACE is an immediate change into the table. I also tested this code on various sample data for your project and they always returned the same value unless I don't have your latest version.
(I noticed a little mistake in the sample code I gave here. The first REPLACE is done on FIELD2 instead of FIELD1. If it changes something)
I get the erroneous result when I put in some values
to toggle the calculated value of FIELD2 from a non-zero to a zero value
or vice-versa. After that, it then seems that my cursor TEMP1 contains
the previous value for FIELD2 and CALCULATE SUM gives a wrong
total but SCAN works.
...some calculations here
...SELECT TABLE1
...REPLACE FIELD2 WITH NewValue &&(toggle between 0 or >0)
*method 1
lnMyTotal=0
SELECT FIELD1, FIELD2, FIELD3 FROM TABLE1;
WHERE FIELD3=myId INTO CURSOR TEMP1
CALCULATE SUM(FIELD1) FOR (FIELD1>0 AND FIELD2>0) TO MyTotal
WAIT WINDOW '1 : ' + STR(lnMyTotal)
*method 2
lnMyTotal=0
SELECT FIELD1, FIELD2, FIELD3 FROM TABLE1;
WHERE FIELD3=myId INTO CURSOR TEMP1
SCAN FOR FIELD1>0 AND FIELD2>0
lnMyTotal = lnMyTotal + FIELD1
ENDSCAN
WAIT WINDOW '2 : ' + STR(lnMyTotal)
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement