Welcome to the LimeSurvey Community Forum

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

Selecting questions based on a custom set of rules

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226050 by Joffm

But I still want to see Joffm's ideas.

Oh, really?
And I tell you it is more or less the same approach.
Of course the code is much more clumpsy. But with the help of W3Schools...
But as it was my first own script I am really proud.

But I used a different way to define the questions.
I joined the values and created eight arrays (8 ttt groups)
The relID is not necessary as it is the same as the id. But you can add it as well. Or you add the number of the corresponding question.
Code:
var questionsArray1 = ["0011A6", "0021A6", "0031A6", "0041A6", "0051A8", "0061A8", "0071A8", "0081A8", "0091C6", "0101C6", "0111C6", "0121C6", "0131C6", "0141C6", "0151C6", "0161C6"];
var questionsArray2 = ["0172A5", "0182A5", "0192A5", "0202A5", "0212A7", "0222A7", "0232A7", "0242A7", "0252B5", "0262B5", "0272B5", "0282B5", "0292B5", "0302B5", "0312B5", "0322B5"];

Now I can capture the ttt-value as "substr(string,3.1)" and the xn-value as "substr(string,4,2)"
Now
1) Shuffle the arrays
2) Add the first objects of each array to a new array "finalArray"
3) Remove those objects from the shuffled arrays
4) Joined the eight arrays to one "restArray"
5) Remove all of the previously selected "xn" values from this array
6) Shuffle the "restArray"
7) Find the first object in this "restArray" and add it to "finalArray"
8) Remove all objects with the same "ttt" value as above from the array
9) Shuffle the "restArray"
10) Again, find the first object in this  array and add it to "finalArray"

Now there are 10 objects in the "finalArray".
Either you load the "substr(string,0,3)" into the question or you leave it for later use of ttt and xn.
As the IDs of array B are only IDArrayA+96 you can easily calculate

Joffm




 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Moathh

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226051 by Joffm
I saw this typo. Of course it is a comma.
But this editor ..
Now I can capture the ttt-value as "substr(string,3,1)" and the xn-value as "substr(string,4,2)"

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: tpartner

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226059 by tpartner
Hi Joffm, thanks for this.

W3Schools is a great resource. :)

I think both approaches have their benefits.

Yours relies on knowing the array lengths and position in strings so may be slightly more efficient.

Mine determines array lengths programmatically and uses more objects than strings so would require slightly more code but may be more flexible.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • Moathh
  • Moathh's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago #226063 by Moathh
Thank you both for the great help, I really appreciate it!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose