Questions collection type object

Available from version 5.4.4.

In AskiaScript, the questions collection object contains a collection of questions. It is, in effect, an array of questions. You can access

You can also create your own collection of questions using the Range() function.

In this topic:

Creating a questions collection object

You can access the entire collection of questions through the Survey.Questions properties and the questions available within the page using CurrentQuestions. You can also create your own collection of questions using the Range() function.

Range(firstQuestion[, lastQuestion])

Available from version 5.4.4.

Creates a collection of questions which contains all questions from the firstQuestion to the lastQuestion.

Returns the Questions Collection.

Parameters
Examples

Collection with only one question

Dim questions = Range(q1)
questions.Count  '=> 1, {q1}

Regular questions within the range

Dim questions = QuestionArray(q1, q5)
questions.Count  '=> 5, {q1; q2; q3; q4; q5} 

Table loop questions within the range

 ' qTableLoop is a question inside a question table tableLoop with 3 iterations

Dim questions = Range(qBeforeLoop, qAfterLoop)
questions.Count  '=> 6, {
' qBeforeLoop; 
' tableLoop;
' qTableLoop.Iteration(1); 
' qTableLoop.Iteration(2); 
' qTableLoop.Iteration(3); 
' qAfterLoop} 

Loop with preliminary selection within the range

 ' qLoopInPreli is a question inside the loop `loopPreli` with preliminary selection 
' `loopPreli.Value` is equal to {1;2;3}

Dim questions = Range(qBeforeLoopPreli, qAfterLoopPreli)
questions.Count  '=> 6, {
' qBeforeLoopPreli; 
' loopPreli; 
' qLoopInPreli.Iteration(1); 
' qLoopInPreli.Iteration(2); 
' qLoopInPreli.Iteration(3); 
' qAfterLoopPreli
' }

Loop with iteration count entry within the range

 ' qLoopInIterCount is a question inside the loop `loopIterCount` with iteration count entry
' `loopIterCount.Value` is equal to {1;2;3} (the user has enter 3)

Dim questions = Range(qBeforeLoopIterCount, qAfterLoopIterCount)
questions.Count  '=> 6, {
' qBeforeLoopIterCount; 
' loopIterCount; 
' qLoopInIterCount.Iteration(1); 
' qLoopInIterCount.Iteration(2); 
' qLoopInIterCount.Iteration(3); 
' qAfterLoopIterCount
' }

Loop with selection at each iteration within the range

 ' qLoopInSelIter is a question inside the loop `loopSelIter` with selection at each iteration
' `loopSetlIter.Value` is equal to {1;2;3} (the user enter 1, then 2, then 3)

Dim questions = Range(qBeforeLoopSelfIter, qAfterLoopSelIter)
questions.Count  '=> 9, {
' qBeforeLoopSelIter; 
' loopSelIter; 
' qLoopInPreli.Iteration(1); 
' qLoopInPreli.Iteration(2); 
' qLoopInPreli.Iteration(3); 
' qAfterLoopPreli
' }

↑ Top of page ↑

Accessors

[index]

Available from version 5.4.4.

Question accessor: returns the question at the specified index. This accessor property is used without the dot or period (.), like an array accessor.

Returns a Question.

Parameters
Examples
Dim questions = Range(q1, q10)
questions[1]  ' => <Question::1#q1>
questions[2]  ' => <Question::2#q2>

↑ Top of page ↑

Properties

Count

Available from version 5.4.4.

Returns the number of items within the collection.

Returns a Number.

Example
Dim questions = Range(q1, q5)
questions.Count ' => 5

↑ Top of page ↑

Errors

Available from version 5.4.4.

Returns the list of errors that occurred during the interview, associated with the questions.

Returns an Array of Errors.

See also: Error

Examples
CurrentQuestions.Errors.Count ' => 3
CurrentQuestions.Errors[1].Key ' => "expected_answer"
CurrentQuestions.Errors[1].Message ' => "A response is expected for question 'q1'"
{% If CurrentQuestions.Errors.Count Then %}
<ul class="questions-errors">
     {% Dim errIter 
        For errIter = 1 To CurrentQuestions.Errors.Count
     %}
        <li>{%= CurrentQuestions.Errors[errITer].Message %}</li>
     {% Next %}
</ul>
{% EndIf %}

Produces:

<ul class="questions-errors">
      <li>Rank 2 is missing for question `Ranking`</li>
      <li>Rank 3 has been given more than once for question `Ranking`</li>
</ul>

↑ Top of page ↑

HasNoData

Available from version 5.4.6.

Indicates whether there is data in all questions (skipped or not skipped). Returns True if at least one question has no data.

Returns a Boolean

' q1.Value is {1}
' q2.Value is "some text"
' q3.Value is 12

Dim questions = Range(q1, q3)
questions.HasNoData ' => False

' q4.Value is DK
' q5.Value is "hello"
' q6.Value is 12

Dim questions = Range(q4, q6)
questions.HasNoData ' => True

↑ Top of page ↑

HasValidData

Available from version 5.4.6.

Indicates if the answers of the questions are valid for open, numeric and closed questions. This method checks if a value is present, and if that value is compatible with the following criteria:

Returns a Boolean.

Examples
' q1.Value is {1}
' q2.Value is "some text"
' q3.Value is 12

Dim questions = Range(q1, q3)
questions.HasValidData ' => True

' q4.Value is {1;2}
' q5.Value is DK ("Don't know is not allowed")
' q6.Value is 12

Dim questions = Range(q4, q6)
questions.HasValidData ' => False

↑ Top of page ↑

Shortcut

Available from version 5.6.1 (November 2024)

Returns the question shortcut (the name of the variable).

Returns a Array of String.

Example
Demographics.ChildQuestions.Shortcut  ' => {"gender";"age";"profession"}

↑ Top of page ↑

Methods

Skip

Available from version 5.6.0.

Equivalent to the routing action do not ask.

Skips the questions and does not keep their data; returns the questions for the call chain.

This is only available when running R/W scripts, not when evaluating conditions.

Returns a Collection of Questions.

If age < 18  Then
   Dim adultQuestions = Range(q10, q20)
   adultQuestions.Skip()
EndIf

↑ Top of page ↑

SkipAndKeepData()

Available from version 5.6.0.

Equivalent to the routing action make question invisible.

Skips the questions and keeps their data; returns the questions for the call chain.

This is only available when running R/W scripts, not when evaluating conditions.

Returns a Collection of Questions.

If age < 18  Then
   Dim adultQuestions = Range(q10, q20)
   adultQuestions.SkipAndKeepData()
EndIf

↑ Top of page ↑

FilterByTag(tags)

Available from version 5.5.0.

Return the list of all the questions with the tag provided as string or the list of tags provided as array of string.

Returns a Collection of Questions.

Parameter
Survey.Questions.FilterByTag("chapter") => 'Return the list of all questions with a tag chapter
Survey.Questions.FilterByTag({"browsable"; "chapter"}) => 'Return the list of all questions with a tag browsable or chapter

↑ Top of page ↑

FilterUnAnswered()

Available from version 5.5.0.

Return the list of all the questions with missing answers for mandatory questions.

Returns a Collection of Questions.

Survey.Questions.FilterUnAnswered() => 'Return the list of all questions with missing answers for mandatory questions.

↑ Top of page ↑

FindByShortcut(shortcut)

Available from version 5.5.0.

Return the question with the exact shortcut.

Returns a Question.

Parameter
Survey.Questions.FindByShortcut("gender") => 'Return the gender question.

↑ Top of page ↑

ToString()

Available from version 5.4.4.

Returns a string which represents the questions collection (expressed in JSON format).

Returns a String.

Example
 ' Output in a single line (it's break here for the readability)
dim questions = Range(q1, q2)
questions.ToString() 
' => [{
"shortcut":"gender", 
"shortCaption":"Respondent gender", 
"longCaption":"Are you?", 
"type":"single" 
},{
"shortcut":"age", 
"shortCaption":"Respondent age", 
"longCaption":"How old are you?", 
"type":"numeric" 
}]

↑ Top of page ↑

TypeOf()

Available from version 5.4.4.

Always return "questions".

Returns a String.

Example
CurrentQuestions.TypeOf() ' => "questions" 

↑ Top of page ↑

Create your own Knowledge Base