Totaling Fields

What is the correct or easiest way to get the total of fields?

Subject: Totaling Fields

Assuming that the fields all have a value, none are left blank:

field1 + field2 + field3 + … + field14

Now if some are potentially blank:

@ToNumber(field1) + @ToNumber(field2) + … + @ToNumber(field14)

finally, if you had a whole bunch of fields that have a pattern to their names, such as subtotal_1, subtotal_2, subtotal3 … subtotal_55

…then I would use a looping @Formula, for instance:

Prefix := “subtotal_”;

x:=0;

total:=0;

@For(n:= 1; n<= 55; n:= n + 1;

fieldname:=Prefix+@Text(n);

x:=@If(

        @IsText(@GetField(fieldname));

                      @ToNumber(@GetField(fieldname));

                      @GetField(fieldname)

      );

total := total + x);

total

See if that will help.

  • Matt