When using if statements, avoid impossible conditional tests.
Example— A incorrect script, which returns myvar is not 5!, even though myvar is 5, because 5 is not the same as five:
You need to know how variables report in various situations. The Console.Writeln() and Alert() methods are especially useful in diagnosing problems related to inaccurate reporting of variables.
Example—A correct script, in which the JavaScript core operator String is used to format myvar for the Console window:
var myvar = 5 Console.Writeln(String(myvar)) if ( myvar == "five") { Alert("myvar = 5!") } else { Alert("myvar is not 5!") }
If you are comparing a value that you selected in a list or drop-down list to another value, verify the retrieved value before you compare it. You want to avoid confusing the placement of the selected item with the value of the selected item.
For example, if a drop–down list contains 4, 9, 15, 25, and 36 and you select 36, the following script returns myvar is 5!:
var myvar = DropDown1.SelectedIndex Console.Writeln(String(myvar)) if ( myvar == 5) { Alert("myvar = 5!") } else { Alert("myvar is not 5!") }
The result occurs because DropDown1.SelectedIndex returns the placement, not the value, of 36.
Consider another example: A drop-down list contains one, two, three, four and five. When you select five, the following script returns myvar = five!
DropDown1 = ActiveDocument.Sections["Dashboard"].Shapes.DropDown1 var myvar = DropDown1.SelectedIndex Console.Writeln(String(myvar)) if ( myvar == 5) { Alert("myvar = five!") } else { Alert("myvar is not five!") }
Five is returned because five is the fifth item. You receive the correct result, but for the wrong reason.
Consider another example: The drop-down list contains the values one, two, three, four, and five. When you select five, the following script returns the value that is displayed in the drop-down list (the correct value, five):