This may be complicated so I am going to attempt to explain as best as I can. There are three relevant questions.
Outside the loop
Q1: Which days of the week do you commute to work [it is a multiple select grid with the columns representing each day.]
--Whatever days they select feeds into the loopList
Loop begins
Q2: what were your commute modes for day 1 (multiple select checkbox)
Q3: was your commute mode for day 2 the same as day 1?
--If they answer 'yes' to this the next loop is skipped.
So, for example say I commute Mon, Tue, Wed.
-- for Q2 Monday I say I drive alone (loop1
-- I then say "yes" for Q3 indicating I also drive alone on Tuesday. so I am not asked Q2 for Tuesday (loop 2).
-- I then say "yes" for Q3 indicating I also drive alone on Wednesday. so I am not asked Q2 for Wednesday (loop 3).
The end goal is to create a variable showing what percent of commute days is spent doing a specific commute mode (e.g. driving alone).
Here is where the code comes in. I have created a quick SawtoothScript run to get the number of days. I got this working and all seems well.
[% SetValue(numberOfDays,(Q1_r1_c1 + Q1_r1_c2 + Q1_r1_c3 + Q1_r1_c4 + Q1_r1_c5 + Q1_r1_c6 + Q1_r1_c7)) %]
The second bit that I have been able to SORT OF get to work is the number of days doing a specific mode.
[% SetValue(countMode,(Q2_19.1 + Q2_19.2 + Q2_19.3 + Q2_19.4 + Q2_19.5 + Q2_19.6 + Q2_19.7) ) %]
This works in that it successfully counts the number of times the variable is checked, BUT because loop2 and loop3 are skipped the value of countMode is 1 when it should really be 3. I am now trying to write a little script in perl that essentially says:
"If Q3 = yes, then populate the next loop instance of Q2 with the previous instance of Q2"
My non-working attempt is here:
if (GETVALUE("Q3.2") == 2) {
SETVALUE("Q3.3",(GETVALUE("Q3.2")));
}
I get Sawtooth Error 269 when I try to run that code.
Update: Since initially starting this thread, I have completely commented out all code and still get the Error 269. However, I can create a new text type question and start over. When I do this I can get the first two code sets to work (numberOfDays and countMode), but when I attempt the Perl I get the Error 269. I then comment out the perl and still get the 269. So I comment out everything and still get 269. Then create a new text type question and repeat.