Actions

ExpressionScript How-tos/ja: Difference between revisions

From LimeSurvey Manual

m (FuzzyBot moved page Expression Manager how-tos/ja to ExpressionScript How-tos/ja without leaving a redirect: Part of translatable page "Expression Manager how-tos")
(Updating to match new version of source page)
Line 1: Line 1:
<languages />
<languages />
__TOC__
__TOC__




=これまでの説明の概略=
=Overview of what has been previously explained=




ここまで、LimeSurveyマニュアルを読めば、[[Expression_Manager_-_presentation/ja#Key_Definitions|LimeSurveyの用語]]を理解したことになります。次に、アンケートを強化する方法として、式と変数について説明しました。次の段階では、[[Expression_Manager_-_presentation/ja#Syntax Highlighting|構文強調表示]]の種類と意味を扱い、構文エラーを修正する方法を学習しました。
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.


これらの基本的な概念をカバーしながら、事例を使ってLimeSurvey内で式がどのように機能するかを説明します。
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.


この構文強調表示によって、複雑なものでも簡単に正しい式を作成することができます。 LimeSurveyチームは式ビルダーGUIの開発を計画していますが、既存の構文強調表示を使用すれば、タイプミスをすばやく特定し修正することができます。また、ツールチップを使用して、式が正しいかを検証することもできます(たとえば、目的の変数を選択したかを確認するなど)。
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)).


それぞれの例では、3つの列があります。
In each of the examples, there are three columns:
#Source - これは、LimeSurveyの質問フィールドに入力する生のテキストです。
#Source - this is the raw text that you would enter into the LimeSurvey question field
#Pretty Print - これは、入力した内容を構文強調表示したものです。
#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.
#*EMは再帰的置換をサポートしているため、強調表示の中で中括弧を表示すると構文エラーが発生する可能性があるので注意してください。
#*Since EM supports recursive substitution, showing curly braces in the highlighting would cause syntax errors
#Result - これは、EMがソースを処理して生成される結果です。
#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:
#: 既知の変数が現在のページに設定されているかどうかに応じて色分けされていることを示します。旧式のINSERTANS:xxxxは独自のカラーコーディングスタイルを持っています。
#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
#数学: 基本的な計算と複雑な計算がサポートされていることを示します。
#Math: shows that basic and complex calculations are supported
#テキスト処理: テキスト処理機能が利用できることを示します。
#TextProcessing: shows some of the available text-processing functions
#日付: 利用可能な日付関連関数のうちの2つを示します。
#Dates: shows two of the available date-related functions
#条件: if()関数の使用法を示します。入れ子にすることもできます。
#Conditional: shows the usage of the if() function. The choices can be nested.
#文言調整された段落: 先行する値に基づいてレポートをカスタマイズすることができます。
#Tailored paragraph: you can completely customize a report based upon prior values
#文字列内のEM処理: 文字列内で置換を実行できることを示します。この例では置換により画像名を生成しています。
#EM processes within strings: shows that it can do substitutions within strings. This example generates a tailored image name.
#EMは中括弧を処理しない: 中括弧がエスケープされているか、式と中括弧の間に空白がある場合、EMはその式を無視します。
#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.




[[File:em-syntax-highlighting-1-v2.jpg]]
<center>[[File:em-syntax-highlighting-1-v2.jpg]]</center>




===エラーを含むEM構文===
==EM Syntax Containing Errors==




EM式を入力する際の一般的なエラーの例を次に示します。ツールチップは追加的な情報を提供します。
Here are examples of common errors when typing EM expressions. Note that the tooltips provide additional information.
#インラインJavascriptで中括弧の後に空白を追加していない。
#Inline Javascript that forgot to add spaces after curly brace
#*EMは、中括弧の直後に"document.write"が現れると式であると考えるため、"document""write"がそれぞれ未定義の変数、関数となり、赤色のボックスで表示される。
#*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/Misspelled variables, functions and operators
#*ここでは、"sex"(性別)の代わりに"gender"という変数名を使用していることを忘れていますが、EMはそのエラーをキャッチします。また、'++'についても、サポートしていない演算子として赤色のボックスで表示されます。
#*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.
#eqの代わりに=を使っていたり、代入を行っている場合の警告
#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.
#関数の引数の数が間違っている
#Wrong number of arguments for functions
#*if()は3つの引数を取りますが、4つ与えられているので、赤いボックスの "if"にカーソルを合わせるとエラーが説明され、サポートされている構文が表示されます。
#*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()は引数の数に制限はありませんが、閉じ括弧の前にコンマがついているので、赤色のボックスで表示されます。
#*sum() takes an unlimited number of arguments, but we had a trailing comma before the closing parentheses, so that is red-boxed
#括弧の不一致
#Mismatched parentheses
#*式を書く時の最も一般的なエラーの一つです。
#*This is one of the most common errors when writing expressions.
#*閉じ括弧が欠落している例を2つ、閉じ括弧が多すぎる例を1つを示しています。
#*This shows two examples of missing closing parentheses, and one example of having one too many closing parentheses.
#サポートされていない構文
#Unsuported syntax
#*EMがサポートしていない演算子または句読点を使用すると、赤いボックスになります。
#*If you use an operator or punctuation that EM does not support, it will red-box it.
#無効な代入
#Invalid assignments
#*変数は値が書き換え可能なものもありますが、読み取り専用のものもあります。
#*Some variables are readWrite and can have their values changed. Others are read-only.
#*読み取り専用変数の値を変更しようとしても実行できません。EMは赤枠で囲みます。
#*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




[[File:em-syntax-highlighting-errors-v2.jpg]]
<center>[[File:em-syntax-highlighting-errors-v2.jpg]]</center>




==アクティブなツールチップを使用した構文ハイライトの"ライブ"の例==
=="Live" examples of Syntax Highlighting with active tooltips==




<table border="1">
<table border="1">
  <tr><th>ソース</th><th>整形表示</th><th>結果</th></tr><tr><td><b>ここでは、ツールチップを使ったOK構文の例を示します。</b><br>こんにちは、{if(gender=='M','Mr.','Mrs.')} {surname}。現在、{date('g:i a',time())}です。数を合わせると{sum(numPets,numKids)}になるあなたの子供とペットがどこにいるかわかりますか。
  <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>ここでは、ツールチップを使ったOK構文の例を示します。</b><br>こんにちは、<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>。現在、<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>です。数を合わせると<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>になるあなたの子供とペットがどこにいるかわかりますか。
</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>ここでは、ツールチップを使ったOK構文の例を示します。</b><br>こんにちは、<span id="LEMtailor_Q_40_1">Mr.</span> <span id="LEMtailor_Q_40_2">Smith</span>。現在、6:07 amです。数を合わせると<span id="LEMtailor_Q_40_4">3</span>になるあなたの子供とペットがどこにいるかわかりますか。
</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>ここでは、ツールチップが表示される一般的なエラーの例を示します。</b><br>宣言する前に変数を使用する:  {notSetYet}<br>未知の関数:  {iff(numPets&gt;numKids,1,2)}<br>未知の変数: {sum(age,num_pets,numKids)}<br>誤った # パラメーター: {sprintf()},{if(1,2)},{date()}<br>読み取り専用の変数への代入:{TOKEN:ATTRIBUTE_1+=10},{name='Sally'}<br>括弧の不一致: {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))}


</td><td><b>ここでは、ツールチップが表示される一般的なエラーの例を示します。</b><br>宣言する前に変数を使用する:  <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>未知の関数:  <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>未知の変数: <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>誤った # パラメーター: <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>読み取り専用の変数への代入:<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>括弧の不一致: <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>


</td><td><b>ここでは、ツールチップが表示される一般的なエラーの例を示します。</b><br>宣言する前に変数を使用する:  <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>未知の関数:  <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>未知の変数: <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>誤った # パラメーター: <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>読み取り専用の変数への代入:<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>括弧の不一致: <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>


</td></tr>
</td></tr>
<tr><td><b>ここでは、サポートされていない構文の例を示します。</b><br>未サポートの'++''--''%'';': {min(++age, --age,age % 2);}<br>'|''&amp;''^': {(sum(2 | 3,3 &amp; 4,5 ^ 6)}}<br>配列: {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>ここでは、サポートされていない構文の例を示します。</b><br>未サポートの'++''--''%'';': <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>'|''&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>配列: <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>


</td><td><b>ここでは、サポートされていない構文の例を示します。</b><br>未サポートの'++''--''%'';': <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>'|''&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>配列: <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>


</td></tr>
</td></tr>
Line 101: Line 99:




=テーラリングの例({INSERTANS:xxx}の拡張)=
=Tailoring Examples (e.g. extending {INSERTANS:xxx})=




Line 107: Line 105:




'Mr.''Mrs.'を使い分けるにはif()関数を使用します。
Use the if() function to conditionally choose whether to display 'Mr.' or 'Mrs.'.


構文は、if(test,do_if_true,do_if_false)です。
The syntax is if(test,do_if_true,do_if_false).


{|
{|
|#||コード||質問||タイプ
|#||Code||Question||Type
|-
|-
|1||gender||性別は?||性別
|1||gender||What is your gender?||Gender
|-
|-
|2||example1||Dear {if(gender=='M','Mr.','Mrs.')} Smith, ...||テキスト表示
|2||example1||Dear {if(gender=='M','Mr.','Mrs.')} Smith, ...||Long free text
|-
|
|}
|}




[[File:em-tailoring-q-ex1.jpg]]
<center>[[File:em-tailoring-q-ex1.jpg]]</center>




使用ビュー:
As it can be observed below, "Mr" and "Mrs" are tailored to what the respondent selects as answer to question "gender".




[[File:em-tailoring-q-ex1-usage.jpg]]
<center>[[File:em-tailoring-q-ex1-usage.jpg]]
[[File:em-tailoring-q-ex2-usage.jpg]]</center>




==案内メールにおける"Dear {Mr}/{Mrs} Smith..."==
=="Dear {Mr}/{Mrs} Smith..." in invitation email==




トークンテーブルの属性を使用して、上記の例を案内メールに使用できます。電子メールの中で'Mr.'または'Mrs.'を使い分けるにはif()関数を使用します。
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.




構文は、if(test,do_if_true,do_if_false)です。
The syntax is "if(test,do_if_true,do_if_false)".


{|
{|
|#||属性||
|#||attribute||value
|-
|-
|-||||Smith
|1||Last name||Smith
|-
|-
|-||メールアドレス||test@test.com
|2||Email address||test@test.com
|-
|-
|-||ATTRIBUTE_2||M
|3||ATTRIBUTE_2||M
|-
|
|}
|}




案内メールのテキスト:
Text in invitation email:


<syntaxhighlight lang="php" enclose="div">
<syntaxhighlight lang="php" enclose="div">
Line 158: Line 153:
Dear {if(ATTRIBUTE_2=='M','Mr','Mrs')} {LASTNAME},
Dear {if(ATTRIBUTE_2=='M','Mr','Mrs')} {LASTNAME},


あなたはアンケートに招待されました。
you have been invited to participate in a survey:


http:/...
https:/...


</syntaxhighlight>
</syntaxhighlight>




[[File:emEx1mail.jpg]]
<center>[[File:emEx1mail.jpg]]</center>




電子メールビュー:
email View:




[[File:emEx1mailview.jpg]]
<center>[[File:emEx1mailview.jpg]]</center>




=計算 / 評価の例=
=Calculation / Assessment Examples=




==実行時に評価値を計算し、その結果をアンケートデータに格納する==
==Calculate assessment values at runtime and store the results in the survey data==




この例では、EMのすべての機能(出現条件、文言調整、式の質問タイプなど)を使用しています。
This example uses all of EM's features, including Relevance, Tailoring, and the Equation question type.


また、これらのすべてがJavaScript対応であることも示しています。したがって、ページにこれらの機能を導入すると、回答者が回答を設定したり変更したりすると、動的に変化します。
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||子どもは何人いますか。||数値入力||1
|1||numKids||How many children do you have?||Numerical input||1
|-
|-
|2||kid1||一番目の子どもは何歳ですか。||数値入力||numKids >= 1
|2||kid1||How old is your first child?||Numerical input||numKids >= 1
|-
|-
|3||kid2||二番目の子どもは何歳ですか。||数値入力||numKids >= 2
|3||kid2||How old is your second child?||Numerical input||numKids >= 2
|-
|-
|4||kid3||三番目の子どもは何歳ですか。||数値入力||numKids >= 3
|4||kid3||How old is your third child?||Numerical input||numKids >= 3
|-
|-
|5||kid4||四番目の子どもは何歳ですか。||数値入力||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)}||||1
|6||sumKidAges||{sum(kid1.NAOK,kid2.NAOK,kid3.NAOK,kid4.NAOK)}||Equation||1
|-
|-
|7||kidSummary||{numKids}人の{if(numKids==1,'子ども','子どもたち')}がいると回答しました。{if(numKids>1,implode(' ','上から',min(numKids,4),'人までの年齢の合計は',sumKidAges,'です。'),' ')}||テキスト表示||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
|-
|
|}
|}




この例をダウンロードするには、次のリンクをクリックしてください。 [[Media:Assessments_survey_example.zip|Assessments_survey_example]]
To download this example, please click on the following link: [[Media:Assessments_survey_example.zip|Assessments_survey_example]].




代表的な質問のスクリーンショットです。ご覧のとおり、EM構文では、文言調整を含んでいそうなすべてのフィールドが強調表示されます。ここでは、出現条件、式の質問タイプ、および質問内の置換の例を示します。ヘルプ、グループヘッダーの表示、ようこそメッセージ、および終了メッセージ内で置き換えることもできます。
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.


この質問では、出現条件は{numKids >= 2}であるため、回答者が少なくとも2人の子供がいると回答した場合にのみ表示されます。
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.




[[File:em-tailoring2-q-kid2.jpg]]
<center>[[File:em-tailoring2-q-kid2.jpg]]</center>




また、各変数に.NAOK接尾辞を使用することに注意してください。これは、EMが入れ子の出現条件を実現するためのものです。もし.NAOKをつけない場合持、4人の子供を持っていると回答した場合にのみ合計が計算されることになります(すべての変数が真の場合)。.NAOKを使用すると、変数のすべてまたは一部が偽であっても合計を計算することを意味します(すなわち"該当なし"(Not Applicable - NA)でも構わないということです)。
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)).


ただし、.NAOK属性は変数がEMに渡されるかどうかにのみ影響します。その人が最初に3人の子供がいると回答し、それぞれの年齢を入力した後、気が変わり、2人であると答えた場合、3つの入力値の合計は必要ありません。次の例で確認してください。
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:




[[File:em-tailoring2-q-sumKidAges.jpg]]
<center>[[File:em-tailoring2-q-sumKidAges.jpg]]</center>




それぞれの式は、黄褐色の背景で色分けされています。ご覧の通り、3つの別々の式があります。最後の式には、2人以上の子供がいる場合にのみ表示されるメッセージが入っています。
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-kidSummary.jpg]]
<center>[[File:em-tailoring2-q-kidSummary.jpg]]</center>




ここでは、実際のアンケートのスクリーンショットを示します。
Now, here are screenshots of the survey in action.


最初にページにアクセスすると、これが表示されます。"0人の'''子ども'''がいます"ではなく、"0人の'''子どもたち'''がいます"となっていることに注意してください。
When you first visit the page, you see this. Note that is says "You have 0 '''children'''" instead of "You have 0 '''child'''".




[[File:em-tailoring2-s-0kids.jpg]]
<center>[[File:em-tailoring2-s-0kids.jpg]]</center>




子どもの数を1に変更すると、同じページ上にあってもこのように表示が即座に変わります。
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-1kid.jpg]]
<center>[[File:em-tailoring2-s-1kid.jpg]]</center>




文法は正しいものになっています。 "You have 1 '''child'''".
Now notice that the grammar is correct: "You have 1 '''child'''".


今度は、子供の数の値を3に変更し、即座に表示を変更します。
Now I change the value for number of children to 3, and the display instantly changes to this.


次の条件付きメッセージが下部に表示されていることに注目してください。"The sum of ages of your first 3 kids is 0.(最初の3人の子供の年齢の合計は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]]
</center>[[File:em-tailoring2-s-3kids.jpg]]</center>




今、子供の年齢を入力し、その年齢を合計して、このように表示させるとします。
Now I'll enter ages for my imaginary children, and I get this display, summing up their ages:




[[File:em-tailoring2-s-3kids-sum.jpg]]
<center>[[File:em-tailoring2-s-3kids-sum.jpg]]</center>




値を入力するとスコアと表示が即座に更新されるため、これを使用して評価スコアの合計を表示することができます。
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.




今度は、子供の数を2に変更します。表示は次のように変わります。
Now, I change the value for the number of children to 2. The display has changed to this:




[[File:em-tailoring2-s-2kids-sum.jpg]]
<center>[[File:em-tailoring2-s-2kids-sum.jpg]]</center>




3番目の子供には5.5の値を入力しましたが、レポートには最初の2人の子供の値が合計されるようになりました。
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.


その理由は、第3の値は出現条件を満たさなくなり、EMはそのような値を無視するからです。
The reason for this is that the 3rd value is now irrelevant, and irrelevant values are actively ignored by EM.


子供の数を3に戻すと、再び5.5という値が見えます。これにより、ページに入力した情報を失うことはありません。
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.


ただし、次または前のページに移動すると、出現条件を満たさない値はすべてセッション内およびデータベース内でNULLになります。もし、子供の数を2と設定したまま次のページに行き、もとのページに戻り、実は3人の子供がいると回答すると、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 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==




この例は、LimeSurvey内の文言調整プロセスを示します。
This example presents the Tailoring process within LimeSurvey.


この例をダウンロードするには、下記のリンクをクリックします。 [[Media:Dynamic_change_of_the_report_when_data_is_entered_on_the_same_page_survey.zip|動的に変化するアンケートの例]]
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]].


これは、ページが最初にどのように見えるかを示しています。どの都市に住んでいるのか尋ねる質問だけがあります。
Here is what the page looks like initially. You only see the question asking what city you live in:




[[File:em-on_page_report-usage-1.jpg]]
<center>[[File:em-on_page_report-usage-1.jpg]]</center>




回答を入力し始めると、文言調整プロセスも開始されます。
Once you start to enter an answer, the tailoring process is also starting:


[[File:em-on_page_report-usage-2.jpg]]
<center>[[File:em-on_page_report-usage-2.jpg]]</center>




回答を入力すると、ページの下部にある表が更新され、回答コードと回答の値が表示されます。
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]]
<center>[[File:em-on_page_report-usage-3.jpg]]</center>


=一般的なデバッグの例=
=Common Debugging Examples=




==ネストされたif()ステートメント(条件付きロジック)==
==Nested if() Statements (Conditional Logic)==




EMは、条件付きロジックまたは文言調整を実行できるよう、関数"if(test,do_if_true,do_if_false)"をサポートしています。この関数は、"if { } else if { } else { }"と同等の処理を行うために入れ子にすることができます。EMは、括弧の数が合わないかどうかを通知します(たとえば、右括弧が消えているなど)か、または余計な右括弧があるかどうかを通知します。長く入れ子になったif文を作成し、保存し、構文エラーをチェックし、見つかった場合は修正してください。以下の例を一緒にチェックしてみましょう。
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:Example_tailoring_group11.zip|Tailoring survey example.lsg]]
The group of questions used below can be accessed from here: [[Media:Example_tailoring_group11.zip|Tailoring survey example.lsg]]




まず何も入力していないときは、単に"Hello."と表示されます。
First, with nothing entered, you just see "Hello."




[[File:em-nested-if-blank.jpg]]
<center>[[File:em-nested-if-blank.jpg]]</center>




名前を入力すると、"Hello {name}."となります。
If you enter a name, it says, "Hello {name}."




[[File:em-nested-if-name.jpg]]
<center>[[File:em-nested-if-name.jpg]]</center>




年齢を入力すると、就学前の子供であるかどうかに応じて調整されたメッセージが届きます。
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-toddler.jpg]]
<center>[[File:em-nested-if-toddler.jpg]]</center>




学齢児童、10代の人、または大人。ここに匿名希望の10代の人がいます。
School aged, teenager, or adult. Here is a  teenager who wants to be anonymous:




[[File:em-nested-if-teenager.jpg]]
<center>[[File:em-nested-if-teenager.jpg]]</center>




ここにグループのロジックファイルがあります。 "if-based"の質問に見られるように、年齢に基づいて入れ子になったif文があります。
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.




[[File:em-nested-if-logic-file.jpg]]
<center>[[File:em-nested-if-logic-file.jpg]]</center>




質問を編集している最中、括弧の数を間違える可能性があります。括弧が少ない場合はこのようになります。
名前を入力すると、"Hello {name}."となります。




[[File:em-nested-if-missing-closing-paren.jpg]]
[[File:em-nested-if-name.jpg]]




赤いボックスで囲まれた"if"という言葉にカーソルを合わせると、"括弧の数が合わない"と表示されます。この例では、"already an adult!"の後ろに4つの閉じ括弧があるはずですが、3つしかありません。
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:




[[File:em-nestedd-if-extra-right-paren.jpg]]
<center>[[File:em-nestedd-if-extra-right-paren.jpg]]</center>




実際に質問を編集しているときは、次のようになります。
When you are actually editing the question, the question looks like this:




[[File:em-nested-if-edit-screen.jpg]]
<center>[[File:em-nested-if-edit-screen.jpg]]</center>

Revision as of 10:15, 3 March 2020


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 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



"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



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



"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:/...



email View:



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.



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:



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.



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".



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:



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.".



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



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:



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:



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


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


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."



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



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



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



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.



名前を入力すると、"Hello {name}."となります。



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:



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