perhaps try giving your variable dimensions and make an array - then you'd have to add code to move the value of amount[1] to amount [2] on each iteration and then you could subtract [1] from [2]... does that get you started?
Jversusj thanks for the help but I have no idea on how to use arrays in Nav. And my values on the variable "amount" is not just two they are numerous. Can you please assist more.
i think you can do this, like i said, with an array.
create your variable and look at the properties. Set the dimensions property to 2 - this will let you keep 2 values in the variable at a time: variable[1] and varibable [2]. then you would do your processing. on your first record (you could be clever to code for the first time it happens versus all subsequent times), you would set variable[2] = your value. variable[1] would be 0. you could then do variable[2] - variable[1].
for all subsequent records you would first say variable[1] := variable[2], then you would set variable[2] equal your new value. you could then do variable[2] - variable[1] as before and get the difference.
so, using your example values:
56.00
86.00
86.00
357.00
389.00
413.00
480.00
etc.
the first time through, set variable[2] := 56.00. there is no previous entry because you just started, so difference := variable[2] - variable[1] would be 56.00. you could code a different formula if you really want the answer to be 0 (according to your example).
the next record would set variable[1] := 56.00 and variable[2] := 86.00, then difference := variable[2] - variable[1].
you would continue this through all records and always subtract the current from the previous.
If it's on a form, then you could do the following :
- Add a Global Variable for your difference ( I'l call it Difference )
- Add a textbox to your tablebox, and add the Difference variable as its SourceExpression
- In the OnAfterGetRecord of the form, declare a variable of the same type as the main record ( let's call it PrevRec )
Prevrec.copy(rec) ;
if PrevRec.next(-1) <> 0 then
//No previous Record found, assume 0 as previous value
PrevRec.init ;
Difference := Rec.Value - Prevrec.value ;
Oh, and do consider that this will look strange if the records aren't sorted on the value you want to use, and filters might do strange things.
boolfirst := true
repeat
actualvalue = tb.amount
if BOOLfirst then begin
BOOLfirst := false;
result := 0;
end else begin
result := actualvalue - previousvalue;
end;
previousvalue := tb.amount;
until tb.next = 0;
***Not tested but should work
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso My Blog
good to hear, although you should note that belias' code does the same thing, without messing with arrays. you would just set up two variables instead of 1 variable with multiple dimensions.
good to hear, although you should note that belias' code does the same thing, without messing with arrays. you would just set up two variables instead of 1 variable with multiple dimensions.
but at least he learnt arrays...which is good!
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso My Blog
Belias I try using your code and when I try compiling it, it says THERE IS A SYNTAX ERROR.
Thanks
Come on! don't blame me so much! (joking)...i forgot a semicolon...hmmm 2 semicolon, 1st and 3rd line...i didn't compile the code pefore posting it... 8)
....and put a findset or find('-') before the repeat :whistle:
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso My Blog
Comments
RIS Plus, LLC
MVP - Business Apps
Amount(decimal)
56.00
86.00
86.00
357.00
389.00
413.00
480.00
it continues
Results
0
86-56
86-86
357-86
389-357
413-357
480-413
it continues
So in each case I want to subtract the first value from the second value.
Thanks.
create your variable and look at the properties. Set the dimensions property to 2 - this will let you keep 2 values in the variable at a time: variable[1] and varibable [2]. then you would do your processing. on your first record (you could be clever to code for the first time it happens versus all subsequent times), you would set variable[2] = your value. variable[1] would be 0. you could then do variable[2] - variable[1].
for all subsequent records you would first say variable[1] := variable[2], then you would set variable[2] equal your new value. you could then do variable[2] - variable[1] as before and get the difference.
so, using your example values:
56.00
86.00
86.00
357.00
389.00
413.00
480.00
etc.
the first time through, set variable[2] := 56.00. there is no previous entry because you just started, so difference := variable[2] - variable[1] would be 56.00. you could code a different formula if you really want the answer to be 0 (according to your example).
the next record would set variable[1] := 56.00 and variable[2] := 86.00, then difference := variable[2] - variable[1].
you would continue this through all records and always subtract the current from the previous.
- Add a Global Variable for your difference ( I'l call it Difference )
- Add a textbox to your tablebox, and add the Difference variable as its SourceExpression
- In the OnAfterGetRecord of the form, declare a variable of the same type as the main record ( let's call it PrevRec )
Oh, and do consider that this will look strange if the records aren't sorted on the value you want to use, and filters might do strange things.
***Not tested but should work
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Thanks
....and put a findset or find('-') before the repeat :whistle:
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog