Script conditions can become complex, and it is good practice to make them as readable as possible. This reduces the possibility of an error in the script, and also makes them easier to understand and modify in future.
When creating a routing instruction, it is often a good idea to add one or more comments, explaining the purpose of the instruction. This makes it easier to for you or for others to understand the questionnaire’s logic at a later date.
To add a comment within a script condition, simply type a single quote (‘). Everything else on that line will be treated as a comment, and ignored when the script runs. For example:
‘True if the respondent answered 1, 2 or 3 to Q2.
Comments are displayed in green in the condition dialog.
You can use the True and False operators to qualify a statement in a script, allowing you to increase the clarity of some conditions that would otherwise be hard to interpret. True and False are used with the logical comparators “=” (equal) and “<>” (not equal). For example:
(Q1 = 2) = True
Conditions in a script are assumed to be true unless specified otherwise, and usually the True operator is omitted. The above statement therefore has the same logical meaning as this one, which is simpler and therefore preferable:
Q1 = 2
However, the following reverses the condition:
(Q1 = 2) = False
It gives the opposite result, i.e. it will be true when Q1 is not 2. It is identical to:
Q1 <> 2
Note that the True operator can also be used as a stand-alone condition (the condition is simply “True”), which tests whether the respondent has reached the screen on which the condition’s start variable is located.
The False operator can be useful in simplifying statements, by allowing you to select on the basis of those who do not meet your criteria, rather than those who do. The following statement is a reasonably complex:
(Q1 = 1 Or Q1 = 3 Or Q1 = 4 Or Q1 = 5) And
(Q2 = 1 Or Q2 = 2 Or Q2 = 3 Or Q2 = 4)
In this example, both Q1 and Q2 are single variables with 5 pre-coded answers.This expression can be made a lot simpler by selecting those who are not 2 at Q1 and not 5 at Q2 (the logical inverse of the first expression):
(Q1 = 2 And Q2 = 5) = False