Check out the LimeSurvey source code on GitHub!

"Else if" in Expression Manager?

More
5 years 4 days ago - 5 years 4 days ago #72042 by Steve01
Hello,

I'm not sure if it is or would be possible to have an
if (a == 1) 'cool'
else if (a == 2) 'not so cool'
else if (a == 3) 'uncool'
else 'I don't know'

I know you can use "if(test,result_if_true,result_if_false)" but i seems to get complicated when you have more than one else part.

I tried
Wow {if(!is_empty(name),implode(' ', ', ', name, ', '),'' )} {if(!is_empty(age),if (age < 5, 'You are kind of young',if (age >= 5 && age < 10, 'Is kindergarden or school fun?',if (age >=10 && age < 18, 'Moah, I want to be an adult right now!', 'You are already an adult!')),'')}
but EM told me
"Parentheses not balanced; Conditional processing; if(test,result_if_true,result_if_false)"
perhaps there is something missing.

Mit freundlichen Grüßen/Best regards,

Stefan Gohlke
LimeSurvey Team
Last Edit: 5 years 4 days ago by Steve01.

Please Log in to join the conversation.

More
5 years 3 days ago #72076 by TMSWhite
vierundzwanzig-

I'm glad to see you're putting EM through its paces.

if/elseif/else clauses can be a pain to deal with in recursive descent parsers, so I didn't try to support them. Yes, when nested if(test,true,false) clauses get deep, they can be a bit of a pain to debug, but if you count parentheses, you can get them right pretty quickly.

Also, the error checker will tell you if you have extra right parentheses. So, unbalanced parentheses mean you're missing at least one right parentheses (perhaps I should update the documentation).

Regardless, you were missing a right parenthesis before the empty string at the end of the if().

Attached is a working version of your test.

File Attachment:

File Name: limesurvey...p_33.lsg
File Size:13 KB


And here is the corrected expression
Wow {if(!is_empty(name),implode(' ', ', ', name, ', '),'' )} {if(!is_empty(age),if (age < 5, 'You are kind of young',if (age >= 5 && age < 10, 'Is kindergarden or school fun?',if (age >=10 && age < 18, 'Moah, I want to be an adult right now!', 'You are already an adult!'))),'')}

Once we have a GUI for EM, I expect we'll try to support parenthesis matching - so if you select a parenthesis, it will highlight the matching one.

/Tom
Attachments:

Please Log in to join the conversation.

More
5 years 3 days ago - 5 years 3 days ago #72081 by Steve01
Thank you, I added the missing parenthesis and it now works.

Parenthesis matching would be kind of nice. Even if the GUI isn't available now, would it be possible to check if the expression is correct when you leave/move out/hover out the text filed (or even before saving a group/question)? If you want to check if your expression works correctly you have to save the question first, then check if it's correct and if not to fix it.

Mit freundlichen Grüßen/Best regards,

Stefan Gohlke
LimeSurvey Team
Last Edit: 5 years 3 days ago by Steve01.

Please Log in to join the conversation.

More
5 years 3 days ago #72113 by Mazi
Good ideas, vierundzwanzig.

I also think that we should extend the EM documentation by adding such forum examples and some .LSS files at the wiki. This should help other users a lot.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 3 days ago #72136 by TMSWhite
Good idea. I added a variant of vierundzwangig's example to the wiki here .

Please Log in to join the conversation.

More
5 years 3 days ago #72144 by Mazi
Thanks!

@others: If you find further examples, please extend the above wiki page.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 4 months ago #85716 by Frankweissman
I have a problem to with a nested if

if(calc_final=6.5, if(finalgrade_thesis= > calc_final, ceil(calc_final), floor(calc_final)), "test")

As you can see it is a test run. However it states I have a comma to much ( after the 6.5)

I have also tried the && function but in that case it states that the if function is not valid.

The calc_final and finalgrade_thesis are working and valid variables (fieldnames)

Hope you can help me out

The function is working in excel ( but then more extended for several situations.
See below
=ALS(I20=5.5;ALS(D15>=I20;AFRONDEN.NAAR.BOVEN(I20;0);AFRONDEN.NAAR.BENEDEN(I20;0));ALS(I20=6.5;ALS(D15>=I20;AFRONDEN.NAAR.BOVEN(I20;0);AFRONDEN.NAAR.BENEDEN(I20;0));ALS(I20=7.5;ALS(D15>=I20;AFRONDEN.NAAR.BOVEN(I20;0);AFRONDEN.NAAR.BENEDEN(I20;0));ALS(I20=8.5;ALS(D15>=I20;AFRONDEN.NAAR.BOVEN(I20;0);AFRONDEN.NAAR.BENEDEN(I20;0));ALS(I20=9.5;ALS(D15>=I20;AFRONDEN.NAAR.BOVEN(I20;0);AFRONDEN.NAAR.BENEDEN(I20;0));AFRONDEN(I20;0))))))

Please Log in to join the conversation.

More
4 years 3 months ago #86158 by Mazi
Please attach your survey or question group for testing.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
2 years 1 week ago - 2 years 1 week ago #116004 by Hiwi_PE
I just imported your suggestion an got the following result:



Obviously the signs have changed somehow.

Are there any ideas for a reason?

Thanks a lot!
Attachments:
Last Edit: 2 years 1 week ago by Hiwi_PE.

Please Log in to join the conversation.

More
2 years 1 week ago #116005 by Mazi
This is a known issue at older versions, see manual.limesurvey.org/Expression_Manager#HTML_editor_issue


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
2 years 1 week ago #116006 by Hiwi_PE
Thank you for your fast and helpful reply!

Please Log in to join the conversation.

More
2 years 1 week ago #116140 by xatarov
I have the same saying as TSMWHITE.....well done

Graduated from Soran University with First Class Degree with Honours in Computer Science.

Please Log in to join the conversation.

More
6 months 2 weeks ago - 6 months 2 weeks ago #138674 by JosB
Have been struggling with this elementary problem for whole day. Hope someone can point me in the right direction. Using 2.5+
In a report we calculate successfully:
Saha dev level {sum(qG01.value,qG02.value,qG03.value,qG04.value,qG05.value,qG06.value,qG07.value,qG08.value,qG09.value)}

I need to use this result in an Else If expression. Tried to place the {sum... above in the expression without joy. Now, am trying INSERTANS but EM does not like it. Tried various ways around with { and with ( and without.

{if {INSERTANS:528299X27X9} < 3, 'This is blocked', if (INSERTANS:528299X27X9 >= 4 && < 8, 'This is normal?')}

What am I doing wrong here?
Thank you
Last Edit: 6 months 2 weeks ago by JosB. Reason: added question

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form