|Related Online Training modules|
|Running a QScript|
|Automate Project Setup with QScripts|
|Generally it is best to access online training from within Q by selecting Help : Online Training|
QScript is an advanced Q feature that can help you to automate repetitive tasks, such as setting up data, cleaning data, recoding data or creating tables and charts. See Rules for tools for manipulating tables and charts.
This page provides an overview of QScript. Refer to:
- QScript Reference for detail about how QScript interacts with Q (i.e., the way to work out the properties of the data).
- QScript Examples Library for examples of using QScript.
QScripts are contained in files with file extension .QScript. There are two ways to run them:
- You can run them from the Online Library using Automate > Online Library. In older versions of Q, instead use Tools > QScripts > Online Library.
- If you have them stored on your computer or network as a file, you can run them using Automate > Run QScript (Macro) From File. In older versions of Q, instead use Tools > Run QScript and Tools > QScript > From File. These files are run in their entirety (i.e., you cannot run just a part of a file).
Creating QScript files
A QScript file can be created in any text editor (a text editor is a word-processor that does not permit formatting). When saving scripts, you must use the ".QScript" file extension.
Q 4.9.4 and onwards
From Q 4.9.4 onwards, there is a in-built editor for QScripts that can be accessed by Automate > Open QScript (Macro) Editor.
Older versions of Q
It is generally not advisable to create QScripts in Word or other Office programs as these programs automatically format text and this automatic formatting can result in difficult-to-find problems.
All Windows computers contain a text editor called Notepad. You can create a QScript in Notepad as follows:
- Start Notepad and type your QScript into it.
- Select File > Save as.
- Type the name for you file as YOUR_FILE_NAME.QScript, replacing YOUR_FILE_NAME with your desired file name.
- Change Save as type to All Files (*.*).
- Press Save.
Some Q features cannot be used by QScript. Contact support if we have left out something important.
The appropriate use of QScript
Many programs can only be used with scripting (e.g., R). Some programs are most efficiently used via scripting (e.g., SPSS’s syntax). In Q, most things are done faster and easier by selecting multiple tables or variables and dragging-and-dropping and using menus. Furthermore, the most repetitious tasks (e.g., re-computing variables when data is updated) are handled automatically by Q. Most users of Q should never need to use QScripts (and, many uses of QScript are better managed using other tools within Q).
Nevertheless, QScript is useful in the following situations:
- When needing to make the same change to a large number of questions (e.g., creating top 2 box scores, such as combining Agree with Strongly agree, on lots of different questions).
- When needing to follow a similar process to the creation and formatting of a large number of tables or charts.
See QScript Examples Library for examples.
This example is designed to illustrate various features of QScript. It
- Starts a new project by reading data in from Q.
- Creates a Banner question.
- Checks for a weight and alerts you that it is not in the file.
- Produces a short report advising you the value used for Don't know.
- Creates some tables and a chart.
To run this example
- Select Automate > Run QScript (Macro) from File (or Tools > Run QScript in Q versions earlier than Q 4.8).
- Select QScript Examples.QScript. This example is located in C:\Program Files\Q\Examples or elsewhere if Q has been installed somewhere else on your computer.
- Press Yes, OK and OK to the different messages.
The following examples from QScript Examples Library contain additional documentation and, if read in order, provide a basic level of training in how to create and use QScript:
This category has the following 2 subcategories, out of 2 total.
- ► QScript Examples Library (2 C, 82 P)
- ► QScript Reference (52 P)
Pages in category ‘QScript’
The following 4 pages are in this category, out of 4 total.