I just started learning FormCalc to help an enduser and came up stuck.
Here's the general form:
Multiple checkboxes,
(name / value when checked)
box1 / 1
box2 / 2
box3 / 3
A numeric field below these 3 boxes needs to calculate the values of those boxes that are checked, then divide by the number of checked boxes
So, if all three boxes are checked, the numeric field would calculate (1 +2 +3) / 3
There are other checkboxes on the form that are not included in this calculation.
I can do multiple if statements :
var total = 0;
if (box1>0) then
total=total+1;
endif
if (box2>0) then
total=total+1;
endif
if (box3>0) then
total=total+1;
endif
if (Eval(total)>0) then
(box1 + box2 + box3) / Eval(total)
endif
I'd like to simplify it with a for statement :
var total = 0;
for a=1 upto 3 do
if (box[a]>0) then
total=total+1;
endif
endfor
if (Eval(total)>0) then
(box1 + box2 + box3) / Eval(total)
endif
But I end up with an error "accessor 'box[1]' is unknown". Which makes sense. The statement is passing the variable, but including the brackets. What am I missing?
TIA