Simple @if question

Trying to get a field ‘GTotal’ to add up and display totals for the fields ‘Costs’ to ‘Costs28’.

Have put in the following but not getting any joy.

@If(Costs=Null;“”;Costs+Cost_1+Costs_2 +Costs_3+Costs_4+Costs_5+Costs_6+Costs_7+Costs_8+Costs_9+Costs_10+Costs_11+Costs_12+Costs_13+Costs_14+Costs_15+Cost_16+Costs_17+Costs_18+Costs_19+Costs_20+Costs_21+ Costs_22 +Costs_23+ Costs_24+Cost_25+Costs_26+Costs_27+Costs_28)

These are all currency fields and have a default value of £0.00

Any pointers please

Subject: Simple @if question

Alex, for numeric fields put this code in their Input Translation:

tmp1:=@If(@IsNumber(Costs) ; “1” ; “0”);

tmp2:=@If(tmp1=“0” ; “” ; Costs);

@If(tmp2!=“” ; @Round(tmp2; 0.01 ) ; “”)

Then for your @if in the GTotal, do this:

n1:=@if(Costs = “” ; 0 ; Costs);

n2:=@if(Cost_1 = “” ; 0 ; Cost_1);

n3:=@if(Cost_2 = “” ; 0 ; Cost_2);

and so on…

n1+n2+n3…etc…

Subject: RE: Simple @if question

Maybe this:

n0:=@If(@IsNumber(Costs);Costs;0);

n1:=@If(@IsNumber(Costs_1);Costs_1;0);

n2:=@If(@IsNumber(Costs_2);Costs_2;0);

n3:=@If(@IsNumber(Costs_3);Costs_3;0);

@Sum(n0;n1;n2;n3)

Subject: RE: Simple @if question

Thanks for the help.

Got the problem sorted cheers.

Subject: Simple @if question

Get out of the Null habit. You can use @IsNull, which is built-in, but there’s nothing to keep an ill-intentioned user (or, worse, a stupid one) from creating a field called Null on documents with a legit value that will screw this up royally.

That being said, why not use @For?

@If(@IsNull(Costs);@Return(“”);“”);

total := Costs;

@For(i := 1; i <= 28; i := i+1;

tempVal := @GetField(“Costs_” + @Text(i));

@If(@IsNull(tempVal; “”; total := total + tempVal));

total