Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Logic error with "if" command

  • YannRaineau
  • YannRaineau's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #239230 by YannRaineau
Logic error with "if" command was created by YannRaineau
Your LimeSurvey version: Version 3.24.3+201027

Dear all,

There must be a very simple answer but as a beginner, I can't find it:
Q1 is a numeric entry "Please state your value:"
Q2 is a randomly generated number "{Q2=if(is_empty(Q2),rand(0,30),Q2)}"

But then, Q3: "{if(Q2>Q1, "hello", "goodbye")}" always replies back "goodbye" whatever the values

Q4 and Q5 are equivalent questions in a simpler case (Q4 is not random anymore but set to 10), but the problem remains.

Do you see what I've done wrong and please tell me?
Thank you in advance!

Please Log in to join the conversation.

  • YannRaineau
  • YannRaineau's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #239231 by YannRaineau
Replied by YannRaineau on topic Logic error with "if" command

File Attachment:

File Name: limesurvey...1626.lss
File Size:17 KB


Here's the file, sorry I forgot it

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago - 1 year 3 months ago #239232 by Joffm
Replied by Joffm on topic Logic error with "if" command
Hi9,
there are several mistakes.

1. In your survey Q2 is a "text display" question, but it should be of type "equation". So you only display something, but nothing is stored.
The same in Q4.
2. {Q2=if(is_empty(Q2),rand(0,30),Q2)}
Here you assign something to another question; unfortunately it is trhe same (Q2)
The correct syntax to generate a random number in a question of type "equation" (Q2) is
{if(is_empty(Q2),rand(0,30),Q2)}
And Q4? You only set the constant {10}

As you read in the manual about the assignment operator

Using assignment operator
The main reasons you may want to use the assignment operator are:
  • You need to set the default value via equation for a question that does not accept default values (such as list radio, where the user interface lets you pick one of the answer options, but does not let you enter an equation). However, be careful, as LimeSurvey will not be able to validate that your equation generates one of the allowable answers for that question;
  • You need to forcibly change the response to a previous question based upon a later response;

Example of assignment:
You can use questions of type "equation" to assign values to other questions, like
{Q2_SQ001=if(Q1_SQ001 gt 3,"Y","")}
{Q2_SQ002=if(Q1_SQ002 gt 3,"Y","")}
{Q2_SQ003=if(Q1_SQ003 gt 3,"Y","")}
Here you preset the subquestions of the (hidden) "multiple" question Q2, if in the "array" question Q1 the subquestions were rated "greater than 3"
Then you can use Q2 as array filter for further questions.

Joffm

Read about ExpressionScript here
[url] manual.limesurvey.org/ExpressionScript_-_Presentation/en [/url]

​​​​​​​

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 3 months ago by Joffm.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago #239237 by holch
Replied by holch on topic Logic error with "if" command
Joffm has already solved your problem.

But I wanted to add:

Your LimeSurvey version: Version 3.24.3+201027


You should seriously consider updating your installation. It hasn't received any update / bug fix / security fix in over 2 years.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

  • YannRaineau
  • YannRaineau's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #239326 by YannRaineau
Replied by YannRaineau on topic Logic error with "if" command
Thank you very much Joffm and holch.
It is fixed when the type is "equation". Yet, I then have trouble editing the question the way I like, but I'll try to manage it by myself and will return to this discussion if I'm still stuck.
Best

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose