Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

While loop: counter in the field name

dherberger
Level 2
Level 2

Here is the code I have. I have tested it and it works on the one number field. (in Formcalc)

if ((FS270Pt1 >= 28.5) and (FS270Pt1 <= 38))

then FS270Pt1.font.fill.color.value = "0,0,0"

else FS270Pt1.font.fill.color.value = "255,0,0"

endif

I have 15 number fields that I need to apply this color font to should the criteria be met.  I am trying to use a While statement to achieve this.  From what I know I have deduced that it would look something like this:

var i = 1

while (i <= 15)

do

     if ((FS270Pt(i) >= 28.5) and (FS270Pt(i) <= 38))

          then FS270Pt(i).font.color.value = "0,0,0"

          else FS270Pt(i).font.color.value = "255,0,0"

     endif

     i = i + 1

endwhile

When I run the 'Check Script Syntax' I do not get any errors.  However, at runtime it states that FS270Pt is unknown.  How can I perform a loop on the binding names of the fields?

1 Accepted Solution
Bibhu_Bikash_Na
Correct answer by
Level 9
Level 9

It will throw error. Because the instances of the field that you are referencing is not correct. You need to loop through the instances of the field. The field name is FS270Pt1. So it's instances witll be FS270Pt1[0], FS270Pt1[1], FS270Pt1[2] ..etc.

So inyour code replace

FS270Pt(i) with FS270Pt1[" + i + "]. It should work.

Thanks,

Bibhu.

View solution in original post

2 Replies
Bibhu_Bikash_Na
Correct answer by
Level 9
Level 9

It will throw error. Because the instances of the field that you are referencing is not correct. You need to loop through the instances of the field. The field name is FS270Pt1. So it's instances witll be FS270Pt1[0], FS270Pt1[1], FS270Pt1[2] ..etc.

So inyour code replace

FS270Pt(i) with FS270Pt1[" + i + "]. It should work.

Thanks,

Bibhu.

View solution in original post

dherberger
Level 2
Level 2

Bibhu,

Thank you very much.  That worked out perfectly for me.  It really sucked though that I had to go back and change all my number field binding names though.  Oh well.  The only thing I did different was I used:

FS270[i] instead of FS270["+i+"]

It works and looks a little cleaner I think.

Thanks again,

Dennis