How to use conditional answer control

The Answer control (Range attribute) can also be used for conditional range control. You can use conditional range control where possible answers are determined by previous answers. This requires som practicing, and can create a very powerful masking. When you grasp the concept, most range controls are possible – even if it may take some scripting.

Example

[gender] is a question about gender.

[position] is a question about your position in your family. You can enter a conditional range for [position] based on the answer given in [gender]

These are the following assumptions you will use:

  • Question type will be a single answer.
  • Question can be left unanswered ( - ).
  • Only a Male can be a Father (1) or a Son (3)
  • Only a Female can be a Mother (2) or a Daughter (4)
  • Both males and females can be other (e.g. grandfather, gradmother)

To accomplish this masking, Select the question [position] and open the Answer control editor.

At the present, the data entry field or answer control is too small for a good edit (this will be improved shortly), so best practice is often to create the conditional statements in a text editor and then paste it into the “answer control” “Programmed logic” field afterwards.

The “When” construct

In the programmed syntax you should insert the following values:

  1. Enter the default list, i.e. values ALWAYS legal (in this case “no answer” and code “5”)
  2. The insert a single space (only one single space)
  3. Then enter the first condition, e.g. Code 1 or 3 is legal when gender is a man
    • 1;3 when \gender.a=1
  4. Insert a new single space (and again: only one single space)
  5. Continue with the next condition, i.e. Code 2 or 4 is legal when gender is a woman
    • 2;4 when \gender.a=2
  6. If there are more conditions, you can specify as many of these as you want.

  7. To finalize the statement (if the list is not so obvious as here, you can use the “else” statement including all other respondents that does not apply to any of the previous conditions
    • In this case the last should be “else 2;4”
  8. The complete syntax should then be

  9. So for a man, the survey will look as this

  10. And for a woman, the survey will look like this

  11. Note: If you are using the “when” (and “else”) in the conditional statements, the selected range will always be the first one in the list that is true. In opposite to this you may use the “try” statements (described below).This method is normally more robust, but is also creates a longer script.

The “Try” construct

As mentioned above, the “Try” construct is normally a more flexible and robust construct, but i requires normally more scripting. Again, at the present, the data entry field or answer control is too small for a good edit (this will be improved shortly), so best practice is often to create the conditional statements in a text editor and then paste it into the “answer control” “Programmed logic” field afterwards.

To accomplish the masking using the “Try” construct, In the “Programmed syntax” you should insert the following values (specifying what condition is legal code by code (or group of codes by group of codes)

  1. Enter the default list, i.e. values ALWAYS legal (in this case “no answer”)
  2. The insert a single space (only one single space)
  3. Then insert the first condition: Code 1 (Father) is allowed if you are a man (code 1 in “gender”)
    • 1 try \gender=1
  4. Insert a new space (only one)
  5. Insert the second condition: Code 2 (mother) is allowed if you are a woman (gender=2)
    • 2 try \gender=2
  6. Insert a new space
  7. Insert the next conditions with a space between until the complete list is finished
  8. - 1 try \gender=1 2 try \gender=2 3 try \gender=1 4 try \gender=2 5 try \gender = 1:2


  9. In this case there are three obvious alternatives that should simplify the statements
  10. -;5 1 try \gender=1 2 try \gender=2 3 try \gender=1 4 try \gender=2
    • Code 5 “other” is always allowed together with “no answer”
  11. -;5;1;3 try \gender=1 -;5;2;4 try \gender=2
    • Specify a complete list for all alternatives
  12. -;5 1;3 try \gender=1 2;4 try \gender=2
    • Very close to the “when” construct, and maybe the most “elegant”

In other words, this needs some practicing, and which manner you choose will be flexible. The code lists may be overlapping i.e. that if you specify a conditional range list based on a multiple question, the final range (based on try statements) will be the logical union of all conditions.

Still need help? Contact Us Contact Us