I'm trying to perform a very basic depreciation calculation based on the age of an asset using a For loop in Crystal 2008, and cannot get it working for the life of me.
The loop looks like this:
NumberVar AssetValue := {CIID.Currency4};
NumberVar DepreciationPercentage := {vw_DepreciationValues.Percent};
NumberVar AssetAge := DateDiff("yyyy",{CIID.Date4},CurrentDate);
Numbervar i := 0;
for i := 0 to AssetAge do
(
AssetValue = AssetValue - ((AssetValue/100)*DepreciationPercentage);
i = i + 1;
);
AssetValue;
For some reason, it always outputs AssetValue as the same number that went in....almost like it gets reset after being run.
I've tested the depreciation formula outside of the loop, and it works fine. I've also verified that the i counter is getting incremented properly by the loop.
Anyone got a clue as to where I'm going wrong? I've even tried creating a custom function using private variables, but it made no difference.
Thanks in advance!
Typos:
AssetValue = AssetValue - ((AssetValue/100)*DepreciationPercentage);
^--- equality test
i = i + 1
^-- ditto
it should be :=
to do an assignment.