Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Questions and responses > Asking questions
 
Asking questions
You ask questions by placing statements in the routing section of the interview script. The simplest way to ask a question is to type:
question_name.Ask()
For example:
RestaurantType.Ask()
EatOutTimes.Ask()
EatInTimes.Ask()
WhenLastEatOut.Ask()
LastEatOut.Ask()
If all questions apply to all respondents and you want to ask the questions in the order they are defined in the metadata section, you can leave the routing section blank. If you want to ask questions in a different order, or you want to apply filtering so that some questions are asked of certain respondents only, then you must write an Ask statement for every question you want to ask.
Asking certain sets of questions only
To ask a subset of questions, use SelectRange. This lets you ask all questions between a starting and ending question (for example, all questions between Q1 and Q5 inclusive) in the order they appear in the metadata section.
Syntax
Put the following statements in the routing section of the script:
Dim variable
For Each variable in IOM.Questions.SelectRange("Qstart..Qend")
  variable.Ask()
Next
Parameters
variable
The name of a temporary variable. You can give the variable any name you like but a name that reflects its purpose is useful.
Qstart
The first question you want to ask.
Qend
The last question you want to ask.
Question names are easiest to use when referring to questions, but you can use a numeric range if you want. However, the interviewing program numbers questions from 0 rather than from 1, so IOM.Questions.SelectRange(1..5) asks the second to sixth questions not the first five questions.
Example
Dim Question For Each Question in       IOM.Questions.SelectRange("TimeBooked..OrganicFood")
  Question.Ask()
Next
Function and sub notes
Do not ask questions in Functions or Subs, as restarts will not work correctly if a restart were to occur on the proceeding question (the script in the Function or Sub after the ask statement will not be executed).
The only exception to this rule is when the .Ask() statement is the last statement executed in a Sub; only a single question or page can be asked. For example, the following script is acceptable:
Sub AskPromotionQ(IOM)

Dim score
score = IOM.Questions.FinalScore

If score >= 100 Then
IOM.Questions.PromotionHigh.Ask()
ElseIf score >= 50 And score < 100 Then
IOM.Questions.PromotionMedium.Ask()
Else
IOM.Questions.PromotionLow.Ask()
End If
End Sub
However, the following example will not restart correctly on timeout and restart:
Sub AskPromotionQs(IOM)

Dim score
score = IOM.Questions.FinalScore

If score >= 100 Then
IOM.Questions.PromotionHigh.Ask()
ElseIf score >= 50 And score < 100 Then
IOM.Questions.PromotionMedium.Ask()
Else
IOM.Questions.PromotionLow.Ask()
End If

' NOT recommended. Only a single Ask statement
' can appear in a sub-routine and it must be the
' last statement executed
IOM.Questions.PromotionFinal.Ask()
End Sub
See also
Questions with categorical responses