Welcome to the LimeSurvey Community Forum

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

Multiple choice - returning a number via expression manager

More
10 years 10 months ago #128135 by jk78
I have a multiple choice question with options:
  • A
  • B
  • C
  • None

Conditions: If a user selects "None" they cannot select any combinations of A, B, or C.

Here are the combinations of answers (8 total):
[none] = 0
A = 1
B = 2
C = 3
A,B = 4
B,C = 5
A,C = 6
A,B,C = 7

For each combination, there is a indice tied to it.

What I am trying to do, is that I pass this data to another application via the form QuestionID=QuestionAnswerCode, where QuestionAnswerCode is the number of the indice tied to the combination chosen for the above question.

When I try to do this, I do the following via the expression manager:
Code:
if( QCode_Selection004 == 'Y', 0, if( QCode_Selection001 == 'Y' && QCode_Selection002 == 'Y' && QCode_Selection003 == 'Y', 7, if( QCode_Selection001 == 'N' && QCode_Selection002 == 'Y' && QCode_Selection003 == 'Y', 6, if( QCode_Selection001 == 'Y' && QCode_Selection002 == 'N' && QCode_Selection003 == 'Y', 5, if( QCode_Selection001 == 'Y' && QCode_Selection002 == 'Y' && QCode_Selection003 == 'N', 4, if( QCode_Selection001 == 'N' && QCode_Selection002 == 'N' && QCode_Selection003 == 'Y', 3, if( QCode_Selection001 == 'N' && QCode_Selection002 == 'Y' && QCode_Selection003 == 'N', 2, if( QCode_Selection001 == 'Y' && QCode_Selection002 == 'N' && QCode_Selection003 == 'N', 1, '') ) ) ) ) ) ) )

But this isn't working. Logically, to me at least, it would appear to make sense. However, given that there are many who are intimately familiar with the Limesurvey system, I am wondering if my approach is either (1) too verbose, (2) correct but has a syntax error or (3) there is a much simpler way of doing this.

Please share your thoughts if you are aware of a similar situation or can help. Thanks!
The topic has been locked.
More
10 years 10 months ago #128140 by DenisChenu
N doesn't exist : checked : use =="Y" OR !is_empty
Not checked : better to use !is_empty.

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The following user(s) said Thank You: jk78
The topic has been locked.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose