Setting a Pick Any Question
		
		
		
		Jump to navigation
		Jump to 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).
var data_file = project.dataFiles[0];
data_file.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
- Next worked example.
 - QScript for an explanation of how to run this code.
 - QScript Examples Library for other examples.
 - QScript Reference for technical information.
 - JavaScript for information about the JavaScript programming language.
 - Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
 - JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.