Can someone tell me why this formula isn’t working? I’m trying to get a total of 12 fields.
Prefix := @Left(@ThisName; “_”);
@For(n := 1;n<=12;
total:= @GetField(Prefix+“_”+@Text(n));
n:=n+1);
total
Can someone tell me why this formula isn’t working? I’m trying to get a total of 12 fields.
Prefix := @Left(@ThisName; “_”);
@For(n := 1;n<=12;
total:= @GetField(Prefix+“_”+@Text(n));
n:=n+1);
total
Subject: @for & @getfield not working
your total:needs to be:
total:= total + @getField(Prefix+“_”+@text(n))
you are just overwriting the total variable w/whatever is in each field… resulting in total equaling fieldname12 value…
Subject: RE: @for & @getfield not working
thx for the quick response!
sorry I’ve been messing around with the code trying to get it to work even in a more simple form.
That was in my original code and it still didn’t work – I get an ‘expected text’ error
Prefix := @Left(@ThisName; “_”);
@For(n := 1;n<=12;
total:= total + @getField(Prefix+“_”+@text(n));
n:=n+1);
total
Subject: @for & @getfield not working
i figured it out…
I built a form w/just 3 fields… just to play with… I was receiving the same error until i initialized the t variable…
you need to initialize your total variable to 0
then it should work…
@If(f1 = “” | f2=“” | f3=“”;@Return(“”);@Success);
t:=0;
@For(n := 1;
n <= 3;
n := n + 1;
fn := “f” + @Text(n);
@prompt([ok];“display fn”;fn);
fv := @getfield(fn);
@prompt([ok];“display fv”;@text(fv));
t := t + fv);
t
Subject: RE: @for & @getfield not working
Thanks so much for your help!! (I love this forum!)
This is what I ended up with - appears to work fine:
x:=0;
total:=0;
Prefix := @Left(@ThisName; “_”);
@For(n:= 1; n<= 12; n:= n + 1;
fieldname:=Prefix+“_”+@Text(n);
x:=@If(@IsText(@GetField(fieldname));@TextToNumber(@GetField(fieldname));@GetField(fieldname));
total := total + x);
total