Actions

Difference between revisions of "Expression Manager how-tos"

From LimeSurvey Manual

(Marked this version for translation)
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<languages />
 +
<translate>
  
 +
 +
<!--T:1-->
 
__TOC__
 
__TOC__
  
This page provides use cases and examples of:
 
*How to convert from using Conditions to using Relevance
 
*How to understand and work with the syntax highlighting
 
*How to take advantage of conditional tailoring
 
*How to easily accomplish, in 1.92, frequently requested features that were hard to do in 1.91+.
 
 
=Introduction=
 
 
LimeSurvey 1.92 uses the new Expression Manager (EM) module which will let LimeSurvey support more complex branching, assessments, validation, and tailoring.  It will replace how LimeSurvey manages Replacements, Conditions, and Assessments on the back-end.  It will also speed up processing considerably since it eliminates most run-time database reads.
 
 
==Key Definitions==
 
#'''Expression''':  Anything surrounded by curly braces
 
#*As long as there is no white space immediately after the opening brace or before the closing curly brace
 
#*The contents of Expressions are evaluted by EM, so they can contain mathematical formulas, functions, and complex string and date processing.
 
#'''Tailoring''': Sometimes called "piping", this is the process of conditionally modifying text
 
#*You have access to all 'replacement fields', TOKENs, and INSERTANS values
 
#*You also have easier access to questions, answers, and their properties.
 
#'''Relevance''' Equation:  A new question attribute controlling question visiblity
 
#*If there is a relevance equation, then the question is only shown if the relevance evaluates to true.
 
#*Internally, all array_filter and array_filter_exclude commands become sub-question-level relevance
 
#'''Equation''' Question Type:  A new question type that saves calculations or reports to the database
 
#*It is like a Boilerplate question, but its contents are saved to the database even if you set "Always Hide this Question"
 
#'''SGQA''':  This is how variables are named in LimeSurvey <= 1.91+
 
#*Stands for Survey-Group-Question-Answer
 
#*SGQA variable names look like 123X5X382X971, and may have sub-question suffixes.
 
#*These variable names are specific to the underlying S/Q/G/A database codes, so often need to be changed
 
#'''Question Code''':  This is the preferred variable name for EM
 
#*This can be a descriptive name indicating the purpose of the question, making it easier to read complex logic
 
#*Although not required to be unique in <= 1.91+, it must be unique if you want to use EM
 
#*Valid question codes should NOT start with a number, so when using the question code to number your questions, simply use "q1", or "q1a" or "g1q2".
 
#*This is what currently becomes the variable name if you export data to SPSS or R, so if you do statistical analysis, you probably already made this unique.
 
  
==Reference documentation==
+
=Overview of what has been previously explained= <!--T:116-->
*[[Expression Manager|Intro and reference for survey authors]]
 
*[[Expression Manager for developers|Details for developers]]
 
  
=Syntax Highlighting=
 
  
To help with entering and validating expressions, EM provides syntax highlighting with the following features:
+
<!--T:117-->
 +
If you have followed so far the structure of the LimeSurvey manual, it means that you already the [[Expression_Manager_-_presentation#Key_Definitions|LimeSurvey terminology]]. Next, we covered expressions and variables in order to learn how to enhance our surveys. In the next part, we moved to the types and meanings of [[Expression_Manager_-_presentation#Syntax Highlighting|syntax highlighting]] to learn how to correct syntax errors.
  
==Types and Meanings of Syntax Highlighting==
+
<!--T:118-->
 +
With these basic notions covered, we could move towards examples and explaining how expressions work within LimeSurvey.
  
{|
 
|Color||Sample||Meaning||Tooltip||Comments
 
|-
 
|tan background||<span style='background:#eee8aa'>Sample</span>||the whole equation||none||Anything within curly braces that is recognized as an equation (e.g. there is no leading or trailing whitepace) will be color-coded with a tan background to help distinguish it from surrounding text
 
|-
 
|blue bold text||'''<span style='color:blue;background:#eee8aa'>Sample</span>'''||function name||meaning and allowable syntax||function names, or things that should be functions since they are followed by an opening parenthesis, are presented in bold blue text.  Tooltips show the meaning and allowable syntax for the function.
 
|-
 
|grey text||<span style='color:grey'>'Sample'</span>||string||none||single and double-quoted strings are shown in grey text
 
|-
 
|bold maroon text||'''<span style='color:maroon;background:#eee8aa'>Sample</span>'''||variable set on the same page, but after the current question||<nowiki>[</nowiki>name or SGQA code]: question; value; answerList showing codes for each value||Any variable that is set on the same page but after the current question is shown in bold maroon text.  This color coding should alert authors to possible errors in question sequencing; but it is allowed since some authors may want this sequence of variables a page, especially for dynamic reports.  The tooltip shows its name (if you used INSERTANS:xxx) or SGQA code (if you used the new naming system), the actual question, and its current value (or blank if not set).  If the question type expects responses from an enumerated value set, the mapping of the codes to display values is show.
 
|-
 
|bold cyan text||'''<span style='color:#4C88BE;background:#eee8aa'>Sample</span>'''||variable set on the same page, prior to the current question||<nowiki>[</nowiki>name or SGQA code]: question; value; answerList showing codes for each value||Any variable that is set on the same page and prior to the current question is shown in bold cyan text.  The tooltip shows its name (if you used INSERTANS:xxx) or SGQA code (if you used the new naming system), the actual question, and its current value (or blank if not set).  If the question type expects responses from an enumerated value set, the mapping of the codes to display values is show.
 
|-
 
|bold green text||'''<span style='color:green;background:#eee8aa'>Sample</span>'''||variable set on a prior page||<nowiki>[</nowiki>name or SGQA code]: question; value; answerList showing codes for each value||Any variable that is set on a prior pageis shown in bold green text.  The tooltip shows its name (if you used INSERTANS:xxx) or SGQA code (if you used the new naming system), the actual question, and its current value (or blank if not set).  If the question type expects responses from an enumerated value set, the mapping of the codes to display values is show.
 
|-
 
|bold pink text||'''<span style='color:#FF00FF;background:#eee8aa'>Sample</span>'''||variable set on a later page||<nowiki>[</nowiki>name or SGQA code]: question; value; answerList showing codes for each value||Any variable that is set on a prior pageis shown in bold pink text.  These are erorrs since the variable is  being used before it is declareed.  The tooltip shows its name (if you used INSERTANS:xxx) or SGQA code (if you used the new naming system), the actual question, and its current value (or blank if not set).  If the question type expects responses from an enumerated value set, the mapping of the codes to display values is show.
 
|-
 
|bold tan text||'''<span style='color:#996600;background:#eee8aa'>Sample</span>'''||a lime relacement value||the value||Lime Replacement Strings (like {TOKEN:xxx}, {PRIVACY_MESSAGE} are shown in bold tan text.  The tooltip shows the current value.
 
|-
 
|red text||'''<span style='color:red,#eee8aa;background:#eee8aa'>Sample</span>'''||assignment operators||warning message||If you use one of the assignment operators (=,+=,-=,*=,/=), that operator will be displayed in red text.  This is meant to help prevent accidental re-assignment of values when you really meant to check whether a == b instead of  setting the value of a = b.
 
|-
 
|normal black text||<span style='color:black;background:#eee8aa'>Sample</span>||punctuation||none||All other punctionation within the expression is shown as normal black text.
 
|-
 
|red-boxed text||<span style='background-color: #eee8aa;'><span title='Undefined variable' style='border-style: solid; border-width: 2px; border-color: red;'>Sample</span></span>||syntax error||description of the error||Any detected syntax errors are shown by surrounding the error with a red box.  The tooltip shows the error.  Examples include unmatched parentheses, use of undefined functions, passing the wrong number of arguments to functions, poorly structured expressions (e.g. missing operators between variables), trying to assign a new value to a read-only variable, trying to assign values to non-variables, or using unsupported syntax.  Note that the syntax error dectection system may only report one error in an expression even if there are multiple errors; however, if any errors are detected, at least one error will be shown.
 
|-
 
|
 
|}
 
  
{{Hint|Text=To be used in javascript, url etc .... a variable must be static in the page. Then the expression must be contain only variable in other page (Green variable)}}
+
=Syntax Highlighting= <!--T:11-->
  
==Examples==
 
  
The following screenshots give examples,  but do not show the values of the tooltips.  If you install the demo and hover the mouse over any of bold colored words, you will see an informative tooltip.
+
<!--T:12-->
 +
The following screenshots give examples, but do not show the values of the tooltips. A tooltip is an informative box which is displayed whenever you hover the mouse over any bold colored words.
  
Note, because of this syntax highlighting, it is very easy to compose correct expressions, even ones that are complicated.  Although the LimeSurvey team plans to try to build an Expression Builder GUI, you can use the existing syntax-highlighting to quickly identify and fix typos.  You can also use the tool-tips to validate the accuracy of your expressions (e.g. confirm you have selected the desired variable(s).
+
<!--T:13-->
 +
Because of this syntax highlighting, it is very easy to compose correct expressions, even the ones that are complicated. Although the LimeSurvey team plans to try to build an Expression Builder GUI, you can use the existing syntax-highlighting to quickly identify and fix typos. You can also use the tooltips to validate the accuracy of your expressions (e.g., confirm you have selected the desired variable(s)).
  
 +
<!--T:14-->
 
In each of the examples, there are three columns:
 
In each of the examples, there are three columns:
#Source - this is the raw text that you would enter into the LimeSurvey Question field
+
#Source - this is the raw text that you would enter into the LimeSurvey question field
 
#Pretty Print - this is the syntax-highlighted equivalent of what you entered
 
#Pretty Print - this is the syntax-highlighted equivalent of what you entered
 
#*Note that Expressions are shown with a tan background, but not surrounded by curly braces in this highlighting.
 
#*Note that Expressions are shown with a tan background, but not surrounded by curly braces in this highlighting.
Line 87: Line 34:
 
#Result - this is the output generated when EM processes the source
 
#Result - this is the output generated when EM processes the source
 
#*Everything that can be properly substituted is
 
#*Everything that can be properly substituted is
#*Expressions with errors are shown in-line, with syntax highlighting.  Errors are surrounded by a red-lined box.
+
#*Expressions with errors are shown in-line, with syntax highlighting. Errors are surrounded by a red-lined box.
  
===Proper Syntax===
 
  
Here are examples of proper syntax:
+
==Proper Syntax== <!--T:15-->
#Values: shows that known variables are color coded according to whether are set on the current page.  Old-style INSERTANS:xxxx gets its own color-coding style
+
 
 +
 
 +
<!--T:16-->
 +
You may find below examples of proper syntax:
 +
#Values: shows that known variables are color coded according to whether are set on the current page. Old-style INSERTANS:xxxx gets its own color-coding style
 
#Question Attributes: shows that dot notation can access some properties of questions
 
#Question Attributes: shows that dot notation can access some properties of questions
 
#Math: shows that basic and complex calculations are supported
 
#Math: shows that basic and complex calculations are supported
 
#TextProcessing: shows some of the available text-processing functions
 
#TextProcessing: shows some of the available text-processing functions
 
#Dates: shows two of the available date-related functions
 
#Dates: shows two of the available date-related functions
#Conditional: shows use of if() function to choose between two choices.  These can be nested.
+
#Conditional: shows the usage of the if() function. The choices can be nested.
#Tailored Paragraph: Shows a more typical example.  You can completely customize a report based upon prior values
+
#Tailored paragraph: you can completely customize a report based upon prior values
#EM processes within strings:  Shows that it can do substitutions within strings.  This example generates a tailored image name.
+
#EM processes within strings: shows that it can do substitutions within strings. This example generates a tailored image name.
#EM doesn't process curly braces like these:  Shows that if the curly braces are escaped, or there is white space between the expression and the curly braces, EM ignores it.
+
#EM doesn't process curly braces like these: shows that if the curly braces are escaped, or there is a white space between the expression and the curly braces, EM ignores the expression.
<nowiki>**</nowiki>This is critical for embedding custom JavaScript.
+
 
 +
 
 +
<!--T:17-->
 +
<center>[[File:em-syntax-highlighting-1-v2.jpg]]</center>
 +
 
  
[[File:em-syntax-highlighting-1-v2.jpg]]
+
==EM Syntax Containing Errors== <!--T:18-->
  
===EM Syntax Containing Errors===
 
  
Here are examples of common errors when typing EM expressions.  Note that the tooltips provide additional information.
+
<!--T:19-->
 +
Here are examples of common errors when typing EM expressions. Note that the tooltips provide additional information.
 
#Inline Javascript that forgot to add spaces after curly brace
 
#Inline Javascript that forgot to add spaces after curly brace
 
#*Since "document.write" appears right after a curly brace, EM thinks it is an expression, and red-boxes "document" and "write" since they are undefined variable and functions, respectively
 
#*Since "document.write" appears right after a curly brace, EM thinks it is an expression, and red-boxes "document" and "write" since they are undefined variable and functions, respectively
#Unknown/Misspelledd Variables, Functions and Operators
+
#Unknown/Misspelled variables, functions and operators
#*Here we forgot that we are using the variable name "gender" instead of "sex", but EM catches that error.  It also red-boxes '++', since that is not a supported operator.
+
#*Here we forgot that we are using the variable name "gender" instead of "sex", but EM catches that error. It also red-boxes '++', since that is not a supported operator.
 
#Warns if use = instead of eq, or perform value assignments
 
#Warns if use = instead of eq, or perform value assignments
#*Note that the '=' and '+=' are in red text instead of black.  If you hover the mouse over them, you will see warnings that you are assigning a value.
+
#*Note that the '=' and '+=' are in red text instead of black. If you hover the mouse over them, you will see warnings that you are assigning a value.
 
#Wrong number of arguments for functions
 
#Wrong number of arguments for functions
#*if() takes 3 arguments, but has been given 4, so hovering over the red-boxed "if" will explain the error and show the supported syntax
+
#*if() takes 3 arguments, but it has been given 4, so hovering over the red-boxed "if" will explain the error and show the supported syntax
 
#*sum() takes an unlimited number of arguments, but we had a trailing comma before the closing parentheses, so that is red-boxed
 
#*sum() takes an unlimited number of arguments, but we had a trailing comma before the closing parentheses, so that is red-boxed
 
#Mismatched parentheses
 
#Mismatched parentheses
Line 123: Line 77:
 
#*If you use an operator or punctuation that EM does not support, it will red-box it.
 
#*If you use an operator or punctuation that EM does not support, it will red-box it.
 
#Invalid assignments
 
#Invalid assignments
#*Some variables are readWrite and can have their values changed. Others are read-only
+
#*Some variables are readWrite and can have their values changed. Others are read-only.
#*If you try to change the value of a read-only variable, you can't.  EM will red-box the attempt.
+
#*If you try to change the value of a read-only variable, you can't. EM will red-box the attempt.
 
#*If you try to assign a value to an equation or a string, you will also get an error
 
#*If you try to assign a value to an equation or a string, you will also get an error
  
[[File:em-syntax-highlighting-errors-v2.jpg]]
+
 
 +
<!--T:20-->
 +
<center>[[File:em-syntax-highlighting-errors-v2.jpg]]</center>
 +
 
 +
 
 +
=="Live" examples of Syntax Highlighting with active tooltips== <!--T:119-->
  
  
==="Live" examples of Syntax Highlighting with active tooltips===
+
<!--T:21-->
 
<table border="1">
 
<table border="1">
  <tr><th>Source</th><th>Pretty Print</th><th>Result</th></tr><tr><td><b>Here is an example of OK syntax with tooltips</b><br>Hello {if(gender=='M','Mr.','Mrs.')} {surname}, it is now {date('g:i a',time())}.  Do you know where your {sum(numPets,numKids)} chidren and pets are?
+
  <tr><th>Source</th><th>Pretty Print</th><th>Result</th></tr><tr><td><b>Here is an example of OK syntax with tooltips</b><br>Hello {if(gender=='M','Mr.','Mrs.')} {surname}, it is now {date('g:i a',time())}.  Do you know where your {sum(numPets,numKids)} children and pets are?
  
</td><td><b>Here is an example of OK syntax with tooltips</b><br>Hello <span style="background-color: #eee8aa;"><span title="Excel-style if(test,result_if_true,result_if_false); if(test,result_if_true,result_if_false)" style="color: blue; font-weight: bold">if</span>(<span title="[java61764X1X5][G:2][Q:110]: What is your gender (male/female)?; value=M" style="color: green; font-weight: bold">gender</span> == <span title="" style="color: gray">'M'</span>,<span title="" style="color: gray">'Mr.'</span>,<span title="" style="color: gray">'Mrs.'</span>)</span> <span style="background-color: #eee8aa;"><span title="[java61764X1X1][G:1][Q:20]: What is your last/surname?; value=Smith" style="color: green; font-weight: bold">surname</span></span>, it is now <span style="background-color: #eee8aa;"><span title="Format a local date/time; string date(format [, timestamp=time()])" style="color: blue; font-weight: bold">date</span>(<span title="" style="color: gray">'g:i a'</span>,<span title="Return current UNIX timestamp; number time()" style="color: blue; font-weight: bold">time</span>())</span>.  Do you know where your <span style="background-color: #eee8aa;"><span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(<span title="[java61764X1X4][G:2][Q:50]: How many pets do you have?; value=1" style="color: maroon; font-weight: bold">numPets</span>,<span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>)</span> chidren and pets are?
+
<!--T:22-->
 +
</td><td><b>Here is an example of OK syntax with tooltips</b><br>Hello <span style="background-color: #eee8aa;"><span title="Excel-style if(test,result_if_true,result_if_false); if(test,result_if_true,result_if_false)" style="color: blue; font-weight: bold">if</span>(<span title="[java61764X1X5][G:2][Q:110]: What is your gender (male/female)?; value=M" style="color: green; font-weight: bold">gender</span> == <span title="" style="color: gray">'M'</span>,<span title="" style="color: gray">'Mr.'</span>,<span title="" style="color: gray">'Mrs.'</span>)</span> <span style="background-color: #eee8aa;"><span title="[java61764X1X1][G:1][Q:20]: What is your last/surname?; value=Smith" style="color: green; font-weight: bold">surname</span></span>, it is now <span style="background-color: #eee8aa;"><span title="Format a local date/time; string date(format [, timestamp=time()])" style="color: blue; font-weight: bold">date</span>(<span title="" style="color: gray">'g:i a'</span>,<span title="Return current UNIX timestamp; number time()" style="color: blue; font-weight: bold">time</span>())</span>.  Do you know where your <span style="background-color: #eee8aa;"><span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(<span title="[java61764X1X4][G:2][Q:50]: How many pets do you have?; value=1" style="color: maroon; font-weight: bold">numPets</span>,<span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>)</span> children and pets are?
  
</td><td><b>Here is an example of OK syntax with tooltips</b><br>Hello <span id="LEMtailor_Q_40_1">Mr.</span> <span id="LEMtailor_Q_40_2">Smith</span>, it is now 6:07 am.  Do you know where your <span id="LEMtailor_Q_40_4">3</span> chidren and pets are?
+
<!--T:23-->
 +
</td><td><b>Here is an example of OK syntax with tooltips</b><br>Hello <span id="LEMtailor_Q_40_1">Mr.</span> <span id="LEMtailor_Q_40_2">Smith</span>, it is now 6:07 am.  Do you know where your <span id="LEMtailor_Q_40_4">3</span> children and pets are?
 
</td></tr>
 
</td></tr>
 
<tr><td><b>Here are common errors so you can see the tooltips</b><br>Variables used before they are declared:  {notSetYet}<br>Unknown Function:  {iff(numPets&gt;numKids,1,2)}<br>Unknown Variable: {sum(age,num_pets,numKids)}<br>Wrong # parameters: {sprintf()},{if(1,2)},{date()}<br>Assign read-only-vars:{TOKEN:ATTRIBUTE_1+=10},{name='Sally'}<br>Unbalanced parentheses: {pow(3,4},{(pow(3,4)},{pow(3,4))}
 
<tr><td><b>Here are common errors so you can see the tooltips</b><br>Variables used before they are declared:  {notSetYet}<br>Unknown Function:  {iff(numPets&gt;numKids,1,2)}<br>Unknown Variable: {sum(age,num_pets,numKids)}<br>Wrong # parameters: {sprintf()},{if(1,2)},{date()}<br>Assign read-only-vars:{TOKEN:ATTRIBUTE_1+=10},{name='Sally'}<br>Unbalanced parentheses: {pow(3,4},{(pow(3,4)},{pow(3,4))}
  
 +
<!--T:24-->
 
</td><td><b>Here are common errors so you can see the tooltips</b><br>Variables used before they are declared:  <span style="background-color: #eee8aa;"><span title="This variable is not declared until a later page; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="This variable is not declared until a later page; Not a valid expression; [java61764X3X6][G:3][Q:200]: Who will win the next election?; value=?" style="color: #FF00FF ; font-weight: bold">notSetYet</span></span></span><br>Unknown Function:  <span style="background-color: #eee8aa;"><span title="Undefined function" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined function" style="color: blue; font-weight: bold">iff</span></span>(<span title="[java61764X1X4][G:2][Q:50]: How many pets do you have?; value=1" style="color: maroon; font-weight: bold">numPets</span> &gt; <span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>,1,2)</span><br>Unknown Variable: <span style="background-color: #eee8aa;"><span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Undefined variable" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined variable" style="color: red; font-weight: bold">num_pets</span></span>,<span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>)</span><br>Wrong # parameters: <span style="background-color: #eee8aa;"><span title="Function must have at least 1 argument(s); Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function must have at least 1 argument(s); Not a valid expression; Return a formatted string; string sprintf(format, arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sprintf</span></span>()</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression; Excel-style if(test,result_if_true,result_if_false); if(test,result_if_true,result_if_false)" style="color: blue; font-weight: bold">if</span></span>(1,2)</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression; Format a local date/time; string date(format [, timestamp=time()])" style="color: blue; font-weight: bold">date</span></span>()</span><br>Assign read-only-vars:<span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; ; value=worker" style="color: #996600; font-weight: bold">TOKEN:ATTRIBUTE_1</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">+=</span>10</span>,<span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; [java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">=</span><span title="" style="color: gray">'Sally'</span></span><br>Unbalanced parentheses: <span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Parentheses not balanced; Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span></span>(3,4</span>,<span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;">(</span><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)</span>,<span style="background-color: #eee8aa;"><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)<span title="Extra right parentheses detected" style="border-style: solid; border-width: 2px; border-color: red;">)</span></span>
 
</td><td><b>Here are common errors so you can see the tooltips</b><br>Variables used before they are declared:  <span style="background-color: #eee8aa;"><span title="This variable is not declared until a later page; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="This variable is not declared until a later page; Not a valid expression; [java61764X3X6][G:3][Q:200]: Who will win the next election?; value=?" style="color: #FF00FF ; font-weight: bold">notSetYet</span></span></span><br>Unknown Function:  <span style="background-color: #eee8aa;"><span title="Undefined function" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined function" style="color: blue; font-weight: bold">iff</span></span>(<span title="[java61764X1X4][G:2][Q:50]: How many pets do you have?; value=1" style="color: maroon; font-weight: bold">numPets</span> &gt; <span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>,1,2)</span><br>Unknown Variable: <span style="background-color: #eee8aa;"><span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Undefined variable" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined variable" style="color: red; font-weight: bold">num_pets</span></span>,<span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>)</span><br>Wrong # parameters: <span style="background-color: #eee8aa;"><span title="Function must have at least 1 argument(s); Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function must have at least 1 argument(s); Not a valid expression; Return a formatted string; string sprintf(format, arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sprintf</span></span>()</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression; Excel-style if(test,result_if_true,result_if_false); if(test,result_if_true,result_if_false)" style="color: blue; font-weight: bold">if</span></span>(1,2)</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression; Format a local date/time; string date(format [, timestamp=time()])" style="color: blue; font-weight: bold">date</span></span>()</span><br>Assign read-only-vars:<span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; ; value=worker" style="color: #996600; font-weight: bold">TOKEN:ATTRIBUTE_1</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">+=</span>10</span>,<span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; [java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">=</span><span title="" style="color: gray">'Sally'</span></span><br>Unbalanced parentheses: <span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Parentheses not balanced; Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span></span>(3,4</span>,<span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;">(</span><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)</span>,<span style="background-color: #eee8aa;"><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)<span title="Extra right parentheses detected" style="border-style: solid; border-width: 2px; border-color: red;">)</span></span>
  
 +
<!--T:25-->
 
</td><td><b>Here are common errors so you can see the tooltips</b><br>Variables used before they are declared:  <span id="LEMtailor_Q_40_5"><span style="background-color: #eee8aa;"><span title="This variable is not declared until a later page; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="This variable is not declared until a later page; Not a valid expression; [java61764X3X6][G:3][Q:200]: Who will win the next election?; value=?" style="color: #FF00FF ; font-weight: bold">notSetYet</span></span></span></span><br>Unknown Function:  <span style="background-color: #eee8aa;"><span title="Undefined function" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined function" style="color: blue; font-weight: bold">iff</span></span>(<span title="[java61764X1X4][G:2][Q:50]: How many pets do you have?; value=1" style="color: maroon; font-weight: bold">numPets</span> &gt; <span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>,1,2)</span><br>Unknown Variable: <span style="background-color: #eee8aa;"><span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Undefined variable" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined variable" style="color: red; font-weight: bold">num_pets</span></span>,<span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>)</span><br>Wrong # parameters: <span style="background-color: #eee8aa;"><span title="Function must have at least 1 argument(s); Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function must have at least 1 argument(s); Not a valid expression; Return a formatted string; string sprintf(format, arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sprintf</span></span>()</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression; Excel-style if(test,result_if_true,result_if_false); if(test,result_if_true,result_if_false)" style="color: blue; font-weight: bold">if</span></span>(1,2)</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression; Format a local date/time; string date(format [, timestamp=time()])" style="color: blue; font-weight: bold">date</span></span>()</span><br>Assign read-only-vars:<span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; ; value=worker" style="color: #996600; font-weight: bold">TOKEN:ATTRIBUTE_1</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">+=</span>10</span>,<span id="LEMtailor_Q_40_12"><span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; [java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">=</span><span title="" style="color: gray">'Sally'</span></span></span><br>Unbalanced parentheses: <span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Parentheses not balanced; Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span></span>(3,4</span>,<span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;">(</span><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)</span>,<span style="background-color: #eee8aa;"><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)<span title="Extra right parentheses detected" style="border-style: solid; border-width: 2px; border-color: red;">)</span></span>
 
</td><td><b>Here are common errors so you can see the tooltips</b><br>Variables used before they are declared:  <span id="LEMtailor_Q_40_5"><span style="background-color: #eee8aa;"><span title="This variable is not declared until a later page; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="This variable is not declared until a later page; Not a valid expression; [java61764X3X6][G:3][Q:200]: Who will win the next election?; value=?" style="color: #FF00FF ; font-weight: bold">notSetYet</span></span></span></span><br>Unknown Function:  <span style="background-color: #eee8aa;"><span title="Undefined function" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined function" style="color: blue; font-weight: bold">iff</span></span>(<span title="[java61764X1X4][G:2][Q:50]: How many pets do you have?; value=1" style="color: maroon; font-weight: bold">numPets</span> &gt; <span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>,1,2)</span><br>Unknown Variable: <span style="background-color: #eee8aa;"><span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Undefined variable" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Undefined variable" style="color: red; font-weight: bold">num_pets</span></span>,<span title="[java61764X1X3][G:2][Q:40]: How many kids do you have?; value=2" style="color: green; font-weight: bold">numKids</span>)</span><br>Wrong # parameters: <span style="background-color: #eee8aa;"><span title="Function must have at least 1 argument(s); Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function must have at least 1 argument(s); Not a valid expression; Return a formatted string; string sprintf(format, arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sprintf</span></span>()</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  2.  Function supports this many arguments, where -1=unlimited: 3; Not a valid expression; Excel-style if(test,result_if_true,result_if_false); if(test,result_if_true,result_if_false)" style="color: blue; font-weight: bold">if</span></span>(1,2)</span>,<span style="background-color: #eee8aa;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Function does not support that number of arguments:  0.  Function supports this many arguments, where -1=unlimited: 1,2; Not a valid expression; Format a local date/time; string date(format [, timestamp=time()])" style="color: blue; font-weight: bold">date</span></span>()</span><br>Assign read-only-vars:<span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; ; value=worker" style="color: #996600; font-weight: bold">TOKEN:ATTRIBUTE_1</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">+=</span>10</span>,<span id="LEMtailor_Q_40_12"><span style="background-color: #eee8aa;"><span title="The value of this variable can not be changed; Not a valid expression" style="border-style: solid; border-width: 2px; border-color: red;"><span title="The value of this variable can not be changed; Not a valid expression; [java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span></span><span title="Assigning a new value to a variable" style="color: red; font-weight: bold">=</span><span title="" style="color: gray">'Sally'</span></span></span><br>Unbalanced parentheses: <span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;"><span title="Parentheses not balanced; Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span></span>(3,4</span>,<span style="background-color: #eee8aa;"><span title="Parentheses not balanced" style="border-style: solid; border-width: 2px; border-color: red;">(</span><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)</span>,<span style="background-color: #eee8aa;"><span title="Exponential expression; number pow(base, exp)" style="color: blue; font-weight: bold">pow</span>(3,4)<span title="Extra right parentheses detected" style="border-style: solid; border-width: 2px; border-color: red;">)</span></span>
  
 +
<!--T:26-->
 
</td></tr>
 
</td></tr>
 
<tr><td><b>Here is some of the unsupported syntax</b><br>No support for '++', '--', '%',';': {min(++age, --age,age % 2);}<br>Nor '|', '&amp;', '^': {(sum(2 | 3,3 &amp; 4,5 ^ 6)}}<br>Nor arrays: {name[2], name['mine']}
 
<tr><td><b>Here is some of the unsupported syntax</b><br>No support for '++', '--', '%',';': {min(++age, --age,age % 2);}<br>Nor '|', '&amp;', '^': {(sum(2 | 3,3 &amp; 4,5 ^ 6)}}<br>Nor arrays: {name[2], name['mine']}
 
</td><td><b>Here is some of the unsupported syntax</b><br>No support for '++', '--', '%',';': <span style="background-color: #eee8aa;"><span title="Find lowest value; number min(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">min</span>(<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ++ </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> -- </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> % </span>2)<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ; </span></span><br>Nor '|', '&amp;', '^': <span style="background-color: #eee8aa;">(<span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> | </span>3,3<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> &amp; </span>4,5<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ^ </span>6)</span>}<br>Nor arrays: <span style="background-color: #eee8aa;"><span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span>2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span>,<span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span><span title="" style="color: gray">'mine'</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span></span>
 
</td><td><b>Here is some of the unsupported syntax</b><br>No support for '++', '--', '%',';': <span style="background-color: #eee8aa;"><span title="Find lowest value; number min(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">min</span>(<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ++ </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> -- </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> % </span>2)<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ; </span></span><br>Nor '|', '&amp;', '^': <span style="background-color: #eee8aa;">(<span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> | </span>3,3<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> &amp; </span>4,5<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ^ </span>6)</span>}<br>Nor arrays: <span style="background-color: #eee8aa;"><span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span>2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span>,<span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span><span title="" style="color: gray">'mine'</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span></span>
  
 +
<!--T:27-->
 
</td><td><b>Here is some of the unsupported syntax</b><br>No support for '++', '--', '%',';': <span style="background-color: #eee8aa;"><span title="Find lowest value; number min(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">min</span>(<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ++ </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> -- </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> % </span>2)<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ; </span></span><br>Nor '|', '&amp;', '^': <span style="background-color: #eee8aa;">(<span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> | </span>3,3<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> &amp; </span>4,5<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ^ </span>6)</span>}<br>Nor arrays: <span style="background-color: #eee8aa;"><span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span>2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span>,<span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span><span title="" style="color: gray">'mine'</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span></span>
 
</td><td><b>Here is some of the unsupported syntax</b><br>No support for '++', '--', '%',';': <span style="background-color: #eee8aa;"><span title="Find lowest value; number min(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">min</span>(<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ++ </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> -- </span><span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span>,<span title="[java61764X1X2][G:2][Q:30]: How old are you?; value=45" style="color: green; font-weight: bold">age</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> % </span>2)<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ; </span></span><br>Nor '|', '&amp;', '^': <span style="background-color: #eee8aa;">(<span title="Calculate the sum of values in an array; number sum(arg1, arg2, ... argN)" style="color: blue; font-weight: bold">sum</span>(2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> | </span>3,3<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> &amp; </span>4,5<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ^ </span>6)</span>}<br>Nor arrays: <span style="background-color: #eee8aa;"><span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span>2<span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span>,<span title="[java61764X1X1][G:1][Q:10]: What is your first/given name?; value=Peter" style="color: green; font-weight: bold">name</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> [ </span><span title="" style="color: gray">'mine'</span><span title="Unsupported syntax" style="border-style: solid; border-width: 2px; border-color: red;"> ] </span></span>
  
 +
<!--T:28-->
 
</td></tr>
 
</td></tr>
 
</table>
 
</table>
  
=Tailoring Examples (e.g. extending {INSERTANS:xxx}=
 
  
=="Dear {Mr}/{Mrs} Smith..."==
+
=Tailoring Examples (e.g. extending {INSERTANS:xxx})= <!--T:29-->
  
 +
 +
=="Dear {Mr}/{Mrs} Smith..."== <!--T:30-->
 +
 +
 +
<!--T:31-->
 
Use the if() function to conditionally choose whether to display 'Mr.' or 'Mrs.'.
 
Use the if() function to conditionally choose whether to display 'Mr.' or 'Mrs.'.
  
 +
<!--T:32-->
 
The syntax is if(test,do_if_true,do_if_false).
 
The syntax is if(test,do_if_true,do_if_false).
  
 +
<!--T:33-->
 
{|
 
{|
 
|#||Code||Question||Type
 
|#||Code||Question||Type
Line 166: Line 138:
 
|1||gender||What is your gender?||Gender
 
|1||gender||What is your gender?||Gender
 
|-
 
|-
|2||example1||Dear {if(gender=='M','Mr.','Mrs.')} Smith, ...||Text display
+
|2||example1||Dear {if(gender=='M','Mr.','Mrs.')} Smith, ...||Long free text
|-
 
|
 
 
|}
 
|}
  
[[File:em-tailoring-q-ex1.jpg]]
 
  
Usage View:
+
<!--T:34-->
 +
<center>[[File:em-tailoring-q-ex1.jpg]]</center>
 +
 
 +
 
 +
<!--T:35-->
 +
As it can be observed below, "Mr" and "Mrs" are tailored to what the respondent selects as answer to question "gender".
 +
 
 +
 
 +
<!--T:36-->
 +
<center>[[File:em-tailoring-q-ex1-usage.jpg]]
 +
[[File:em-tailoring-q-ex2-usage.jpg]]</center>
  
[[File:em-tailoring-q-ex1-usage.jpg]]
 
  
=="Dear {Mr}/{Mrs} Smith..." in invitation email==
+
=="Dear {Mr}/{Mrs} Smith..." in invitation email== <!--T:37-->
  
 +
 +
<!--T:38-->
 
You can use the example above in the invitation email using attributes from the token table. Use the if() function to choose whether 'Mr.' or 'Mrs.' should be used in the email.
 
You can use the example above in the invitation email using attributes from the token table. Use the if() function to choose whether 'Mr.' or 'Mrs.' should be used in the email.
  
The syntax is if(test,do_if_true,do_if_false).
 
  
 +
<!--T:39-->
 +
The syntax is "if(test,do_if_true,do_if_false)".
 +
 +
<!--T:40-->
 
{|
 
{|
 
|#||attribute||value
 
|#||attribute||value
 
|-
 
|-
|-||Last name||Smith
+
|1||Last name||Smith
 
|-
 
|-
|-||Email address||test@test.com
+
|2||Email address||test@test.com
 
|-
 
|-
|-||ATTRIBUTE_2||M
+
|3||ATTRIBUTE_2||M
|-
 
|
 
 
|}
 
|}
  
 +
 +
<!--T:41-->
 
Text in invitation email:
 
Text in invitation email:
  
 +
<!--T:42-->
 
<syntaxhighlight lang="php" enclose="div">
 
<syntaxhighlight lang="php" enclose="div">
  
 +
<!--T:43-->
 
Dear {if(ATTRIBUTE_2=='M','Mr','Mrs')} {LASTNAME},
 
Dear {if(ATTRIBUTE_2=='M','Mr','Mrs')} {LASTNAME},
  
 +
<!--T:44-->
 
you have been invited to participate in a survey:
 
you have been invited to participate in a survey:
  
http:/...
+
<!--T:45-->
 +
https:/...
  
 +
<!--T:46-->
 
</syntaxhighlight>
 
</syntaxhighlight>
  
[[File:emEx1mail.jpg]]
 
  
 +
<!--T:47-->
 +
<center>[[File:emEx1mail.jpg]]</center>
 +
 +
 +
<!--T:48-->
 
email View:
 
email View:
  
[[File:emEx1mailview.jpg]]
 
  
=Calculation / Assessment Examples=
+
<!--T:49-->
 +
<center>[[File:emEx1mailview.jpg]]</center>
  
==Calculate assessment values at runtime and store the results in the survey data==
 
  
 +
=Calculation / Assessment Examples= <!--T:50-->
 +
 +
 +
==Calculate assessment values at runtime and store the results in the survey data== <!--T:51-->
 +
 +
 +
<!--T:52-->
 
This example uses all of EM's features, including Relevance, Tailoring, and the Equation question type.
 
This example uses all of EM's features, including Relevance, Tailoring, and the Equation question type.
  
It also shows that all of these are JavaScript-enabled, so if you have these features on a page, it will dynamically change as people set and change their answers.
+
<!--T:53-->
 +
It also shows that all of them are JavaScript-enabled, so if you have these features on a page, it will dynamically change as people set and change their answers.
  
 +
<!--T:54-->
 
{|
 
{|
 
|#||Code||Question||Type||Relevance
 
|#||Code||Question||Type||Relevance
Line 234: Line 234:
 
|5||kid4||How old is your fourth child?||Numerical input||numKids >= 4
 
|5||kid4||How old is your fourth child?||Numerical input||numKids >= 4
 
|-
 
|-
|6||sumKidAges||{sum(kid1.NAOK,kid2,NAOK,kid3.NAOK,kid4.NAOK)}||Equation||1
+
|6||sumKidAges||{sum(kid1.NAOK,kid2.NAOK,kid3.NAOK,kid4.NAOK)}||Equation||1
 
|-
 
|-
 
|7||kidSummary||You said that you have {numKids}. {if(numKids==1,'child','children')}. {if(numKids>1,implode(' ','The sum of ages of your first ',min(numKids,4),' kids is ',sumKidAges,'.'),' ')}||Text display||1
 
|7||kidSummary||You said that you have {numKids}. {if(numKids==1,'child','children')}. {if(numKids>1,implode(' ','The sum of ages of your first ',min(numKids,4),' kids is ',sumKidAges,'.'),' ')}||Text display||1
|-
 
|
 
 
|}
 
|}
  
Here are screen shots of representative questions.  As you can see, EM syntax-highlights all fields that might contain tailoring.  Here, you see examples of syntax-highlighting Relevance, the Equation question type, and substitions within a Question.  However, you can also put substitutions within Help, Group header display, the Welcome message, and the End message.
 
  
For this question, since the relevance is {numKids >= 2), it will only be visible if the respondant reports that they have at least two children.
+
<!--T:120-->
 +
To download this example, please click on the following link: [[Media:Assessments_survey_example.zip|Assessments_survey_example]].
 +
 
 +
 
 +
<!--T:55-->
 +
You may find below screenshots of representative questions. As you can see, EM syntax-highlights all fields that might contain tailoring. Here, you see examples of syntax-highlighting Relevance, the Equation question type, and substitutions within a question. You can also use substitutions within Help, Group header display, Welcome message, and End message.
 +
 
 +
<!--T:56-->
 +
In the next example, since the relevance is {numKids >= 2), the question will only be visible if the respondent reports that she has at least two children.
 +
 
 +
 
 +
<!--T:57-->
 +
<center>[[File:em-tailoring2-q-kid2.jpg]]</center>
 +
 
 +
 
 +
<!--T:59-->
 +
Below, you may observe that each variable has the .NAOK suffix attached to it. This is because of how EM supports cascading relevance. If you did not have .NAOK, then the sum would only be computed if the person said she has 4 children (e.g., if all of the variables are relevant). The usage of .NAOK means that we want to compute the sum even if all or some of the variables are irrelevant (e.g., "Not Applicable" (NA) is alright (OK)).
 +
 
 +
<!--T:60-->
 +
However, the .NAOK attribute only affects whether variables are passed into EM. If the respondent initially says she has 3 children, and enters ages for each, then changes her mind and says she has 2, we don't want to see the sum of the 3 entered values - since the third child is "not applicable" in our case anymore:
 +
 
 +
 
 +
<!--T:61-->
 +
<center>[[File:em-tailoring2-q-sumKidAges.jpg]]</center>
 +
 
 +
 
 +
<!--T:62-->
 +
Each separate Expression is color coded with a tan background. As you can see, there are three separate Expressions here. The last one contains a message that is conditionally shown only if the person has more than one child.
  
[[File:em-tailoring2-q-kid2.jpg]]
 
  
Note that this question uses the new Equation type, and that despite being "Always hidden", the result will be computed and stored to the database.
+
<!--T:63-->
 +
<center>[[File:em-tailoring2-q-kidSummary.jpg]]</center>
  
Also note that is uses the .NAOK suffix for each variable.  This is because of how EM supports cascading relevance.  If you did not have .NAOK, then the sum would only be computed if the person said they had 4 children (e.g. if all of the variables are relevant).  By using .NAOK, that means that we want to compute the sum even if all or some of the variables are irrelevant (e.g. "Not Applicable" (NA) is alright (OK)).
 
  
However, the .NAOK attribute only affects whether variables are passed into EM.  If the person initially says they have 3 children, and enters ages for each, then changes their mind and says they have 2, we don't want to see the sum of the 3 entered values - see below for an example of this.
+
<!--T:64-->
 +
Now, here are screenshots of the survey in action.
  
[[File:em-tailoring2-q-sumKidAges.jpg]]
+
<!--T:65-->
 +
When you first visit the page, you see this. Note that is says "You have 0 '''children'''" instead of "You have 0 '''child'''".
  
Each separate Expression is color coded with a tan background.  As you can see, three separate Expressions here.  The last one contains a message that is conditionally shown only if the person has more than one child.
 
  
[[File:em-tailoring2-q-kidSummary.jpg]]
+
<!--T:66-->
 +
<center>[[File:em-tailoring2-s-0kids.jpg]]</center>
  
Now, here are screen shots of the survey in action.
 
  
When you first visit the page, you see this.   Note that is says "You have 0 '''children'''" instead of "You have 0 '''child'''".
+
<!--T:67-->
 +
If I change the value for number of children to 1, the display instantly changes to this, even though it is on the same page:
  
[[File:em-tailoring2-s-0kids.jpg]]
 
  
If I change the value for number of children to 1, the display instantly changes to this, even though it is on the same page.
+
<!--T:69-->
 +
<center>[[File:em-tailoring2-s-1kid.jpg]]</center>
  
Now notice that the grammar is correct, is says, "You have 1 '''child'''".
 
  
[[File:em-tailoring2-s-1kid.jpg]]
+
<!--T:68-->
 +
Now notice that the grammar is correct: "You have 1 '''child'''".
  
 +
<!--T:70-->
 
Now I change the value for number of children to 3, and the display instantly changes to this.
 
Now I change the value for number of children to 3, and the display instantly changes to this.
  
 +
<!--T:71-->
 
Notice that you now see the conditional message at the bottom:  "The sum of ages of your first 3 kids is 0.".
 
Notice that you now see the conditional message at the bottom:  "The sum of ages of your first 3 kids is 0.".
  
[[File:em-tailoring2-s-3kids.jpg]]
 
  
Now I'll enter ages for my imaginary children, and I get this display, summing their ages.
+
<!--T:72-->
 +
</center>[[File:em-tailoring2-s-3kids.jpg]]</center>
 +
 
  
 +
<!--T:73-->
 +
Now I'll enter ages for my imaginary children, and I get this display, summing up their ages:
 +
 +
 +
<!--T:75-->
 +
<center>[[File:em-tailoring2-s-3kids-sum.jpg]]</center>
 +
 +
 +
<!--T:74-->
 
Again, the score and display updates instantly as I enter the values, so you can use this to show a running total of an Assessment Score.
 
Again, the score and display updates instantly as I enter the values, so you can use this to show a running total of an Assessment Score.
  
[[File:em-tailoring2-s-3kids-sum.jpg]]
 
  
Now, I change the value for the number of children to 2, and the display instantly changes to this.
+
<!--T:76-->
 +
Now, I change the value for the number of children to 2. The display has changed to this:
  
 +
 +
<!--T:79-->
 +
<center>[[File:em-tailoring2-s-2kids-sum.jpg]]</center>
 +
 +
 +
<!--T:77-->
 
Notice that although I had entered a value of 5.5 for the third child, the report now only sums the values of my first 2 children.
 
Notice that although I had entered a value of 5.5 for the third child, the report now only sums the values of my first 2 children.
  
 +
<!--T:78-->
 
The reason for this is that the 3rd value is now irrelevant, and irrelevant values are actively ignored by EM.
 
The reason for this is that the 3rd value is now irrelevant, and irrelevant values are actively ignored by EM.
  
[[File:em-tailoring2-s-2kids-sum.jpg]]
+
<!--T:80-->
 +
If I were to change the number of kids back to 3, I would see the value of 5.5 I entered again. So, I don't lose any information I enter on the page.
  
Note, if I were to change the number of kids back to 3, I would see the value of 5.5 I entered, so I don't lose any information I enter on the page.
+
<!--T:81-->
 +
However, if I navigate to the Next or Previous page, all irrelevant values will be NULLed out in the session and in the database. So, if I were to keep the value at 2, go to the next page, and then come back and state that I actually have 3 kids, I would no longer see the age of 5.5.
  
However, if I navigate to the Next or Previous page, all irrelevant values will be NULLed out in the session and in the database.  So, if I were to keep the value at 2, go to the next page and come back, then say  that I had 3 kids, I would no longer see the age of 5.5.
 
  
==Enter data and see a dynamically changing report of what was entered on the same page==
+
==Enter data and see a dynamically changing report of what was entered on the same page== <!--T:82-->
  
This example uses two of EM's features:  Relevance and Tailoring.
 
  
Rather than summarizing the questions as a table, the actual LimeSurvey group file is attached so you can try it yourself.
+
<!--T:83-->
 +
This example presents the Tailoring process within LimeSurvey.
  
Here is what the page looks like initially.  You only see the question asking what City you live in.
+
<!--T:84-->
 +
To download this example, click on the following link: [[Media:Dynamic_change_of_the_report_when_data_is_entered_on_the_same_page_survey.zip|Dynamic changes survey example]].
  
[[File:em-on_page_report-usage-1.jpg]]
+
<!--T:85-->
 +
Here is what the page looks like initially. You only see the question asking what city you live in:
  
Once you start to enter an answer, the rest of the questions appear.
 
  
[[File:em-on_page_report-usage-2.jpg]]
+
<!--T:86-->
 +
<center>[[File:em-on_page_report-usage-1.jpg]]</center>
  
 +
 +
<!--T:87-->
 +
Once you start to enter an answer, the tailoring process is also starting:
 +
 +
<!--T:88-->
 +
<center>[[File:em-on_page_report-usage-2.jpg]]</center>
 +
 +
 +
<!--T:89-->
 
As you enter answers, the table at the bottom of the page is updated to show the answer codes and values of your responses.
 
As you enter answers, the table at the bottom of the page is updated to show the answer codes and values of your responses.
  
[[File:em-on_page_report-usage-3.jpg]]
 
  
Here is the bottom of the page, which shows that you can either use {INSERTANS:xxxx} or the newer naming system interchangeably.
+
<!--T:90-->
 +
<center>[[File:em-on_page_report-usage-3.jpg]]</center>
  
[[File:em-on_page_report-usage-4.jpg]]
+
=Common Debugging Examples= <!--T:93-->
  
=Common Debugging Examples=
 
  
==Nested if() Statements (Conditional Logic)==
+
==Nested if() Statements (Conditional Logic)== <!--T:94-->
  
EM supports the function if(test,do_if_true,do_if_false) so that you can perform conditional logic or tailoring.  This function can be nested to do the equivalent of if { } else if { } else {  }.  EM will let you know if the parentheses are not balanced (e.g. you are missing a closing right parenthesis), or if you have any extra right parentheses.  You should try to count the parentheses as you compose long nested if statements, save it, check for syntax errors, and fix them if any are found.  Here is an example:
 
  
Here is the group file for these examples:
+
<!--T:95-->
 +
EM supports the function "if(test,do_if_true,do_if_false)" so that you can perform conditional logic or tailoring. This function can be nested to do the equivalent of "if { } else if { } else {  }". EM will let you know if the parentheses are not balanced (e.g., you are missing a closing right parenthesis), or if you have any extra right parentheses. You should try to count the parentheses as you compose long nested if statements, save it, check for syntax errors, and fix them if any are found. Let's check together the below example.
  
[[Media:limesurvey_group_33.lsg|limesurvey_group_33.lsg]]
+
<!--T:96-->
 +
The group of questions used below can be accessed from here: [[Media:Example_tailoring_group11.zip|Tailoring survey example.lsg]]
  
 +
 +
<!--T:98-->
 
First, with nothing entered, you just see "Hello."
 
First, with nothing entered, you just see "Hello."
  
[[File:em-nested-if-blank.jpg]]
 
  
 +
<!--T:99-->
 +
<center>[[File:em-nested-if-blank.jpg]]</center>
 +
 +
 +
<!--T:100-->
 
If you enter a name, it says, "Hello {name}."
 
If you enter a name, it says, "Hello {name}."
  
[[File:em-nested-if-name.jpg]]
 
  
If you enter an age, you get a tailored message, depending upon whether you are a pre-school-age child:
+
<!--T:101-->
 +
<center>[[File:em-nested-if-name.jpg]]</center>
  
[[File:em-nested-if-toddler.jpg]]
 
  
School aged, teenager, or adult.  Here is a  teenager who wants to be anonymous:
+
<!--T:102-->
 +
If you enter an age, you get a tailored message, depending upon whether you are a pre-school-age child or not:
  
[[File:em-nested-if-teenager.jpg]]
 
  
Here is the logic file for the group.  As you can see in the iftest question, there are nested if statements based upon the person's age.
+
<!--T:103-->
 +
<center>[[File:em-nested-if-toddler.jpg]]</center>
  
[[File:em-nested-if-logic-file.jpg]]
 
  
When you are originally editing this question, it is likely that at some point, you will have the wrong number of parentheses.  Here's what happens if you have too few.
+
<!--T:104-->
 +
School aged, teenager, or adult. Here is a  teenager who wants to be anonymous:
  
[[File:em-nested-if-missing-closing-paren.jpg]]
 
  
If you hover over the word "if" which is surrounded by a red box, it says "Parentheses not balanced".  In this case, there should be three closing parentheses after "already an adult!", but there are only two.
+
<!--T:105-->
 +
<center>[[File:em-nested-if-teenager.jpg]]</center>
  
 +
 +
<!--T:106-->
 +
Here is the logic file of the group. As you can see in the "if-based" question, there are nested if statements based upon the person's age.
 +
 +
 +
<!--T:107-->
 +
<center>[[File:em-nested-if-logic-file.jpg]]</center>
 +
 +
 +
<!--T:108-->
 +
When you are originally editing this question, it is likely that at some point, you will have the wrong number of parentheses. Here's what happens if you have too few:
 +
 +
 +
<!--T:109-->
 +
<center>[[File:em-nested-if-missing-closing-paren.jpg]]</center>
 +
 +
 +
<!--T:110-->
 +
If you hover over the word "if", which is surrounded by a red box, it says "Parentheses not balanced". In this case, there should be four closing parentheses after "already an adult!", but there are only three.
 +
 +
<!--T:111-->
 
If, on the other hand, you have an extra right parenthesis, it will be surrounded by a red box, like this:
 
If, on the other hand, you have an extra right parenthesis, it will be surrounded by a red box, like this:
  
[[File:em-nestedd-if-extra-right-paren.jpg]]
 
  
When you are actually editing the question, it looks like this:
+
<!--T:112-->
 +
<center>[[File:em-nestedd-if-extra-right-paren.jpg]]</center>
 +
 
 +
 
 +
<!--T:113-->
 +
When you are actually editing the question, the question looks like this:
 +
 
 +
 
 +
<!--T:114-->
 +
<center>[[File:em-nested-if-edit-screen.jpg]]</center>
  
[[File:em-nested-if-edit-screen.jpg]]
 
  
In the future, we hope to have to ability to dynamically syntax-highlight these equations while you are editing them. Most programming  editors, for example, will highlight the matching parentheses or curly braces.  For now, however, you just have to count opening and closing if parentheses (the same way you might in Excel), save your best guess, and check the syntax highlighting for errors.
+
</translate>

Latest revision as of 20:36, 17 October 2018

Other languages:
English • ‎日本語 • ‎Nederlands



Overview of what has been previously explained

If you have followed so far the structure of the LimeSurvey manual, it means that you already the LimeSurvey terminology. Next, we covered expressions and variables in order to learn how to enhance our surveys. In the next part, we moved to the types and meanings of syntax highlighting to learn how to correct syntax errors.

With these basic notions covered, we could move towards examples and explaining how expressions work within LimeSurvey.


Syntax Highlighting

The following screenshots give examples, but do not show the values of the tooltips. A tooltip is an informative box which is displayed whenever you hover the mouse over any bold colored words.

Because of this syntax highlighting, it is very easy to compose correct expressions, even the ones that are complicated. Although the LimeSurvey team plans to try to build an Expression Builder GUI, you can use the existing syntax-highlighting to quickly identify and fix typos. You can also use the tooltips to validate the accuracy of your expressions (e.g., confirm you have selected the desired variable(s)).

In each of the examples, there are three columns:

  1. Source - this is the raw text that you would enter into the LimeSurvey question field
  2. Pretty Print - this is the syntax-highlighted equivalent of what you entered
    • Note that Expressions are shown with a tan background, but not surrounded by curly braces in this highlighting.
    • Since EM supports recursive substitution, showing curly braces in the highlighting would cause syntax errors
  3. Result - this is the output generated when EM processes the source
    • Everything that can be properly substituted is
    • Expressions with errors are shown in-line, with syntax highlighting. Errors are surrounded by a red-lined box.


Proper Syntax

You may find below examples of proper syntax:

  1. Values: shows that known variables are color coded according to whether are set on the current page. Old-style INSERTANS:xxxx gets its own color-coding style
  2. Question Attributes: shows that dot notation can access some properties of questions
  3. Math: shows that basic and complex calculations are supported
  4. TextProcessing: shows some of the available text-processing functions
  5. Dates: shows two of the available date-related functions
  6. Conditional: shows the usage of the if() function. The choices can be nested.
  7. Tailored paragraph: you can completely customize a report based upon prior values
  8. EM processes within strings: shows that it can do substitutions within strings. This example generates a tailored image name.
  9. EM doesn't process curly braces like these: shows that if the curly braces are escaped, or there is a white space between the expression and the curly braces, EM ignores the expression.


Em-syntax-highlighting-1-v2.jpg


EM Syntax Containing Errors

Here are examples of common errors when typing EM expressions. Note that the tooltips provide additional information.

  1. Inline Javascript that forgot to add spaces after curly brace
    • Since "document.write" appears right after a curly brace, EM thinks it is an expression, and red-boxes "document" and "write" since they are undefined variable and functions, respectively
  2. Unknown/Misspelled variables, functions and operators
    • Here we forgot that we are using the variable name "gender" instead of "sex", but EM catches that error. It also red-boxes '++', since that is not a supported operator.
  3. Warns if use = instead of eq, or perform value assignments
    • Note that the '=' and '+=' are in red text instead of black. If you hover the mouse over them, you will see warnings that you are assigning a value.
  4. Wrong number of arguments for functions
    • if() takes 3 arguments, but it has been given 4, so hovering over the red-boxed "if" will explain the error and show the supported syntax
    • sum() takes an unlimited number of arguments, but we had a trailing comma before the closing parentheses, so that is red-boxed
  5. Mismatched parentheses
    • This is one of the most common errors when writing expressions.
    • This shows two examples of missing closing parentheses, and one example of having one too many closing parentheses.
  6. Unsuported syntax
    • If you use an operator or punctuation that EM does not support, it will red-box it.
  7. Invalid assignments
    • Some variables are readWrite and can have their values changed. Others are read-only.
    • If you try to change the value of a read-only variable, you can't. EM will red-box the attempt.
    • If you try to assign a value to an equation or a string, you will also get an error


Em-syntax-highlighting-errors-v2.jpg


"Live" examples of Syntax Highlighting with active tooltips

SourcePretty PrintResult
Here is an example of OK syntax with tooltips
Hello {if(gender=='M','Mr.','Mrs.')} {surname}, it is now {date('g:i a',time())}. Do you know where your {sum(numPets,numKids)} children and pets are?
Here is an example of OK syntax with tooltips
Hello if(gender == 'M','Mr.','Mrs.') surname, it is now date('g:i a',time()). Do you know where your sum(numPets,numKids) children and pets are?
Here is an example of OK syntax with tooltips
Hello Mr. Smith, it is now 6:07 am. Do you know where your 3 children and pets are?
Here are common errors so you can see the tooltips
Variables used before they are declared: {notSetYet}
Unknown Function: {iff(numPets>numKids,1,2)}
Unknown Variable: {sum(age,num_pets,numKids)}
Wrong # parameters: {sprintf()},{if(1,2)},{date()}
Assign read-only-vars:{TOKEN:ATTRIBUTE_1+=10},{name='Sally'}
Unbalanced parentheses: {pow(3,4},{(pow(3,4)},{pow(3,4))}
Here are common errors so you can see the tooltips
Variables used before they are declared: notSetYet
Unknown Function: iff(numPets > numKids,1,2)
Unknown Variable: sum(age,num_pets,numKids)
Wrong # parameters: sprintf(),if(1,2),date()
Assign read-only-vars:TOKEN:ATTRIBUTE_1+=10,name='Sally'
Unbalanced parentheses: pow(3,4,(pow(3,4),pow(3,4))
Here are common errors so you can see the tooltips
Variables used before they are declared: notSetYet
Unknown Function: iff(numPets > numKids,1,2)
Unknown Variable: sum(age,num_pets,numKids)
Wrong # parameters: sprintf(),if(1,2),date()
Assign read-only-vars:TOKEN:ATTRIBUTE_1+=10,name='Sally'
Unbalanced parentheses: pow(3,4,(pow(3,4),pow(3,4))
Here is some of the unsupported syntax
No support for '++', '--', '%',';': {min(++age, --age,age % 2);}
Nor '|', '&', '^': {(sum(2 | 3,3 & 4,5 ^ 6)}}
Nor arrays: {name[2], name['mine']}
Here is some of the unsupported syntax
No support for '++', '--', '%',';': min( ++ age, -- age,age % 2) ;
Nor '|', '&', '^': (sum(2 | 3,3 & 4,5 ^ 6)}
Nor arrays: name [ 2 ] ,name [ 'mine' ]
Here is some of the unsupported syntax
No support for '++', '--', '%',';': min( ++ age, -- age,age % 2) ;
Nor '|', '&', '^': (sum(2 | 3,3 & 4,5 ^ 6)}
Nor arrays: name [ 2 ] ,name [ 'mine' ]


Tailoring Examples (e.g. extending {INSERTANS:xxx})

"Dear {Mr}/{Mrs} Smith..."

Use the if() function to conditionally choose whether to display 'Mr.' or 'Mrs.'.

The syntax is if(test,do_if_true,do_if_false).

# Code Question Type
1 gender What is your gender? Gender
2 example1 Dear {if(gender=='M','Mr.','Mrs.')} Smith, ... Long free text


Em-tailoring-q-ex1.jpg


As it can be observed below, "Mr" and "Mrs" are tailored to what the respondent selects as answer to question "gender".


Em-tailoring-q-ex1-usage.jpg Em-tailoring-q-ex2-usage.jpg


"Dear {Mr}/{Mrs} Smith..." in invitation email

You can use the example above in the invitation email using attributes from the token table. Use the if() function to choose whether 'Mr.' or 'Mrs.' should be used in the email.


The syntax is "if(test,do_if_true,do_if_false)".

# attribute value
1 Last name Smith
2 Email address test@test.com
3 ATTRIBUTE_2 M


Text in invitation email:

Dear {if(ATTRIBUTE_2=='M','Mr','Mrs')} {LASTNAME},

you have been invited to participate in a survey:

https:/...


EmEx1mail.jpg


email View:


EmEx1mailview.jpg


Calculation / Assessment Examples

Calculate assessment values at runtime and store the results in the survey data

This example uses all of EM's features, including Relevance, Tailoring, and the Equation question type.

It also shows that all of them are JavaScript-enabled, so if you have these features on a page, it will dynamically change as people set and change their answers.

# Code Question Type Relevance
1 numKids How many children do you have? Numerical input 1
2 kid1 How old is your first child? Numerical input numKids >= 1
3 kid2 How old is your second child? Numerical input numKids >= 2
4 kid3 How old is your third child? Numerical input numKids >= 3
5 kid4 How old is your fourth child? Numerical input numKids >= 4
6 sumKidAges {sum(kid1.NAOK,kid2.NAOK,kid3.NAOK,kid4.NAOK)} Equation 1
7 kidSummary You said that you have {numKids}. {if(numKids==1,'child','children')}. {if(numKids>1,implode(' ','The sum of ages of your first ',min(numKids,4),' kids is ',sumKidAges,'.'),' ')} Text display 1


To download this example, please click on the following link: Assessments_survey_example.


You may find below screenshots of representative questions. As you can see, EM syntax-highlights all fields that might contain tailoring. Here, you see examples of syntax-highlighting Relevance, the Equation question type, and substitutions within a question. You can also use substitutions within Help, Group header display, Welcome message, and End message.

In the next example, since the relevance is {numKids >= 2), the question will only be visible if the respondent reports that she has at least two children.


Em-tailoring2-q-kid2.jpg


Below, you may observe that each variable has the .NAOK suffix attached to it. This is because of how EM supports cascading relevance. If you did not have .NAOK, then the sum would only be computed if the person said she has 4 children (e.g., if all of the variables are relevant). The usage of .NAOK means that we want to compute the sum even if all or some of the variables are irrelevant (e.g., "Not Applicable" (NA) is alright (OK)).

However, the .NAOK attribute only affects whether variables are passed into EM. If the respondent initially says she has 3 children, and enters ages for each, then changes her mind and says she has 2, we don't want to see the sum of the 3 entered values - since the third child is "not applicable" in our case anymore:


Em-tailoring2-q-sumKidAges.jpg


Each separate Expression is color coded with a tan background. As you can see, there are three separate Expressions here. The last one contains a message that is conditionally shown only if the person has more than one child.


Em-tailoring2-q-kidSummary.jpg


Now, here are screenshots of the survey in action.

When you first visit the page, you see this. Note that is says "You have 0 children" instead of "You have 0 child".


Em-tailoring2-s-0kids.jpg


If I change the value for number of children to 1, the display instantly changes to this, even though it is on the same page:


Em-tailoring2-s-1kid.jpg


Now notice that the grammar is correct: "You have 1 child".

Now I change the value for number of children to 3, and the display instantly changes to this.

Notice that you now see the conditional message at the bottom:  "The sum of ages of your first 3 kids is 0.".


Em-tailoring2-s-3kids.jpg


Now I'll enter ages for my imaginary children, and I get this display, summing up their ages:


Em-tailoring2-s-3kids-sum.jpg


Again, the score and display updates instantly as I enter the values, so you can use this to show a running total of an Assessment Score.


Now, I change the value for the number of children to 2. The display has changed to this:


Em-tailoring2-s-2kids-sum.jpg


Notice that although I had entered a value of 5.5 for the third child, the report now only sums the values of my first 2 children.

The reason for this is that the 3rd value is now irrelevant, and irrelevant values are actively ignored by EM.

If I were to change the number of kids back to 3, I would see the value of 5.5 I entered again. So, I don't lose any information I enter on the page.

However, if I navigate to the Next or Previous page, all irrelevant values will be NULLed out in the session and in the database. So, if I were to keep the value at 2, go to the next page, and then come back and state that I actually have 3 kids, I would no longer see the age of 5.5.


Enter data and see a dynamically changing report of what was entered on the same page

This example presents the Tailoring process within LimeSurvey.

To download this example, click on the following link: Dynamic changes survey example.

Here is what the page looks like initially. You only see the question asking what city you live in:


Em-on page report-usage-1.jpg


Once you start to enter an answer, the tailoring process is also starting:

Em-on page report-usage-2.jpg


As you enter answers, the table at the bottom of the page is updated to show the answer codes and values of your responses.


Em-on page report-usage-3.jpg

Common Debugging Examples

Nested if() Statements (Conditional Logic)

EM supports the function "if(test,do_if_true,do_if_false)" so that you can perform conditional logic or tailoring. This function can be nested to do the equivalent of "if { } else if { } else {  }". EM will let you know if the parentheses are not balanced (e.g., you are missing a closing right parenthesis), or if you have any extra right parentheses. You should try to count the parentheses as you compose long nested if statements, save it, check for syntax errors, and fix them if any are found. Let's check together the below example.

The group of questions used below can be accessed from here: Tailoring survey example.lsg


First, with nothing entered, you just see "Hello."


Em-nested-if-blank.jpg


If you enter a name, it says, "Hello {name}."


Em-nested-if-name.jpg


If you enter an age, you get a tailored message, depending upon whether you are a pre-school-age child or not:


Em-nested-if-toddler.jpg


School aged, teenager, or adult. Here is a  teenager who wants to be anonymous:


Em-nested-if-teenager.jpg


Here is the logic file of the group. As you can see in the "if-based" question, there are nested if statements based upon the person's age.


Em-nested-if-logic-file.jpg


When you are originally editing this question, it is likely that at some point, you will have the wrong number of parentheses. Here's what happens if you have too few:


Em-nested-if-missing-closing-paren.jpg


If you hover over the word "if", which is surrounded by a red box, it says "Parentheses not balanced". In this case, there should be four closing parentheses after "already an adult!", but there are only three.

If, on the other hand, you have an extra right parenthesis, it will be surrounded by a red box, like this:


Em-nestedd-if-extra-right-paren.jpg


When you are actually editing the question, the question looks like this:


Em-nested-if-edit-screen.jpg