Variables
Previous Topic  Next Topic 

Referring to a variable

In most cases variables are referenced by enclosing them with double braces, e.g. {{Asset}}.

In question prompts

Using double braces means that variables can be embedded within fixed text strings such as question prompts.

The above example shows a question Asset followed by another question regarding its location. Inserting the value of the Asset question into the prompt makes it more meaningful to the user. So if the user had selected say, "chair" from the Asset menu, then the following question would display "Where is the chair located?"

In hints

At the moment hints are only available in Number questions. At runtime hints appear on the status line at the bottom of the screen and can be used to provide additional information to the user, e.g. a question asking for a quantity of materials may display the unit of measure as a hint

In messages

Messages may be used to display some meaningful information to the user or, if you are developing a new questionnaire, you may wish to use them temporarily to display intermediate results. As with prompts and hints, messages can also contain embedded variables.

Used with the Calculator

Here we have Unit cost and Quantity statements followed by a Total cost calculation. The Total cost calculation uses the results of the previous statements so:

Is it a variable or a literal?

Before PocketSurvey Designer displays a variable reference it checks to see if it actually exists. If it does then it leaves the double braces as they are. If it does not exist then the braces are replaced with double quotes. In the previous calculator example we referred to a variable Quantity. If we were to change the name of the Quantity statement to say, Enter a quantity then PocketSurvey would no longer be able to tie up the reference and would show it so:

Scoping

So far we have used variables that are all in the same section, these are known as local variables. What if we want to use variables from another section? The answer is to use dotted variables. Probably the easiest way to see this is in the Calculation statement's expression helper.

Here we have chosen GENERAL DWELLING DETAILS from the Section list. The Variables list now shows all the variables that are available from that section. Choosing Dwelling type inserts the correctly formed reference into the Expression editor.

If we Cut and Paste or Copy this statement into another section then it will still use the GENERAL DWELLING DETAILS.Dwelling type variable. Sometimes we may simply want to refer to a variable in the parent section, i.e. the section containing the current section. To do this we use a special section reference 'PARENT'. This has the basic form {{PARENT.variable}}.

Initial value

The initial value field is an exception to the general rule that variables have to be enclosed by double braces. Here the variables (always local) are displayed in the drop-down list and are used as they are - without decoration. There is a special variable that always appears in the list called Use previous; at run time this uses the previous answer to the question as the initial value.

Built-in variables

We have already seen the variable Use previous, but here are some other useful built-in variables:

_MainQuestionAnswer

This contains the answer given to the current question. It is only available within the COMMON section.

_MainQuestionSection

This contains the name of the section containing the current main question. It is only available within the COMMON section.

_MainQuestionName

This contains the current question prompt (not the data name).

_MenuScore

This contains the score for the most recently used menu. It is normally used within the COMMON section but it is available anywhere.

_Cloned

This will be "TRUE" if the user has chosen to clone the current survey from an existing one, otherwise it will be "FALSE"

_ClonedFrom

If the user has cloned the current survey from an existing one then this will contain the identifier of the survey that was chosen as the clone source.

N.B. Both this variable and the '_Cloned' variable will contain "" and "FALSE" respectively if the survey is re-entered. It is up to the survey designer to save any values set on initial entry and to check for them if the survey is re-entered.

HandHeld Systems Ltd ©