Setting a Pick Any Question

From Q
Jump to: navigation, search

Identifies variables with a common prefix in their variable name and combines these as a Pick Any question. This example uses C:\Program Files\Q\Examples\Phone.sav (this may be located on a different place on your computer depending upon how Q was installed).


project.dataFiles[0].setQuestion('Q5', 'Pick Any', data_file.getVariablesByName("Q5_"));

Note that:

  • The question type has to be specified (in this example, a Pick Any question is created).
  • data_file.getVariablesByName("Q5_") returns an array of all the variables that have Name beginning with Q5_. Alternatively, we could have created an array, using square brackets, using getVariableByName and specified each of the variables individually:
data_file.setQuestion('Q5', 'Pick Any',[data_file.getVariableByName("Q5_1"),
data_file.getVariableByName("Q5_2"),
data_file.getVariableByName("Q5_3"),
data_file.getVariableByName("Q5_4"),
data_file.getVariableByName("Q5_5"),
data_file.getVariableByName("Q5_6"),
data_file.getVariableByName("Q5_7"),
data_file.getVariableByName("Q5_8"),
data_file.getVariableByName("Q5_9"),
data_file.getVariableByName("Q5_10"),
data_file.getVariableByName("Q5_11")]);

See also