Copy link to clipboard
Copied
I'm running the following code and my for loop is aborting at * n=42 *
Can anyone see why?
var f = this.getField("cbEdit");
var n = 0
for (var n=16;i<=112;n++){
app.alert(n);
if(n<70 || n>71){
{
s=n+"";
if(f.isBoxChecked(0)){
this.getField("CBR"+s).display = display.visible;
this.getField("CBV"+s).display = display.visible;
this.getField("CBM"+s).display = display.visible;
this.getField("Post"+s).display = display.visible;
}
else {
this.getField("CBR"+s).display = display.hidden;
this.getField("CBV"+s).display = display.hidden;
this.getField("CBM"+s).display = display.hidden;
this.getField("Post"+s).display = display.hidden;
}
}
}
}
Copy link to clipboard
Copied
Check the Javascript console for errors. The script will stop when a field doesn't exists.
And why does you use this:
i<=112
Copy link to clipboard
Copied
Thanks Bernd! Yup ... I had a miss in the fields name sequence. I should have known that without having to post.
Reason: All fields within the loop value set are modified.
Copy link to clipboard
Copied
Just as Bernd said, check the console for errors. It's very likely a problem with a non-existing field.
There are a few things I would change in your script:
As Bernd also pointed out, you are mixing variables in your for loop. You initialize and increment "n", but your loop condition uses "i".
There is an extra set of {} in the loop.
The expression "if (n < 70 || n > 71)" should probably be rewritten to "if (n != 71)", that's easier to understand than the two combined expressions.
It is not necessary to convert "n" to "s" by adding an emtpy string. You are doing the conversion from integer to string when you create the field name (e.g. "CBR" + s). If you want to make sure that you have a string, there is an explicit "to string" conversion built into Javascript: You can either use n.toString() or String(n) to force the conversion.
Hope that helps.
Copy link to clipboard
Copied
Thanks Karl!
Changed the i to n for testing and missed one.
Where are the {}'s not necessary?
The expression excludes 70 & 71
I see your "n" to "s" point - thanks for the string advice.
Cheers!
Copy link to clipboard
Copied
Ah now I see that you are excluding two values.
Here is the code with two comments added that point to the curly braces in question:
var f = this.getField("cbEdit");
var n = 0
for (var n = 16; i <= 112; n++) {
app.alert(n);
if (n < 70 || n > 71) {
{ // <-- this is extra
s = n + "";
if (f.isBoxChecked(0)) {
this.getField("CBR" + s).display = display.visible;
this.getField("CBV" + s).display = display.visible;
this.getField("CBM" + s).display = display.visible;
this.getField("Post" + s).display = display.visible;
} else {
this.getField("CBR" + s).display = display.hidden;
this.getField("CBV" + s).display = display.hidden;
this.getField("CBM" + s).display = display.hidden;
this.getField("Post" + s).display = display.hidden;
}
} // <-- this is extra
}
}
Anytime I look at code, I bring it into my editor and let it format the code. This will make things like that obvious.
Copy link to clipboard
Copied
Got it Karl ... Thanks!!
What editor do you use? Any good open source you would recommend?
Copy link to clipboard
Copied
Most of my development is done on a Mac, that's where I use TextMate. On the PC, I use NotePad++ with the JavaScript package JSTool installed. NotePad++ is free.
Copy link to clipboard
Copied
THX Karl!