This script creates a conditional sequence that compares two Numeric questions. The participant enters into the questions found in the conditional sequence if the value of the response to the first question being compared is greater than the value of the response to the second question being compared.
Detailed Steps
Create the Conditional Sequence
- In the Questionnaire tab of your study, create a new conditional sequence.
- Select the conditional sequence in the tree.
- Expand the Properties section below the Filter Editor.
- Under Condition Using: select Script.
- Click Save.
Prepare the Script
- Open Notepad or a similar text editing tool.
- Copy the script below into Notepad.
- Replace q1_NumericQuestion with the name of the first numeric question.
- Replace q2_NumericQuestion with the name of the second numeric choice question.
- Save the completed script in Notepad.
/* Script Name: How do I add a conditional sequence based on comparing two numeric questions? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ EnterCondition = false; VerbatimQuestion vq1 = q1_NumericQuestion; VerbatimQuestion vq2 = q2_NumericQuestion; if((double)vq1.NumberValue > (double)vq2.NumberValue) { EnterCondition = true; }
Note: The question names used in scripts are case-sensitive. Ensure that you use the exact question names as they appear in the Questionnaire tree of the study.
Insert the Script
- Copy the completed script from Notepad and paste it into the Conditional Sequence textbox in the questionnaire.
- Click Save.
- Create questions in the Conditional Sequence. These questions will be answered by those who enter the conditional sequence based on the criteria (i.e. the IF statement) presented in the script.
- Click Validate.
Conditional Values used by If statements in C#:
The following table presents the Conditional values used by if-statements in C# scripting.
Condition | C# Scripting Operator |
Equal To | == |
Not Equal To | != |
Greater Than | > |
Less Than | < |
Greater or Equal To | >= |
Less Than or Equal To | <= |
More Example Scripts
The following script presents the questions in the Conditional Sequence if the respondent provides an answer with a lower value in the first question than in the second:
/* Script Name: How do I add a conditional sequence based on comparing two numeric questions? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ EnterCondition = false; VerbatimQuestion vq1 = q1_NumericQuestion; VerbatimQuestion vq2 = q2_NumericQuestion; if((double)vq1.NumberValue < (double)vq2.NumberValue) { EnterCondition = true; }
The following script presents the questions in the Conditional Sequence if the respondent provides answers with different values in both questions:
/* Script Name: How do I add a conditional sequence based on comparing two numeric questions? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ EnterCondition = false; VerbatimQuestion vq1 = q1_NumericQuestion; VerbatimQuestion vq2 = q2_NumericQuestion; if((double)vq1.NumberValue != (double)vq2.NumberValue) { EnterCondition = true; }
Comments
0 comments
Article is closed for comments.