Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Block Randomization doesn't work

My study contains 10 blocks of questions.
The respondents should either conduct block 1-5 or block 6-10.
So i've tried my best and created a parent list called "BlockList" with 10 predefined list members. (1,2,3,4... and so on).

Afterwards i created a constructed list based on BlockList with the following code:

Begin Unverified Perl
my$RandNum=SYSRAND(1,2);
          if($RandNum==1)
          {
                    ADD("BlockList",1,2,3,4,5);
          }
          else
          {
                    ADD("BlockList",6,7,8,9,10);
          }
End Unverified
asked Jan 11 by Honeybadger Bronze (535 points)

1 Answer

0 votes
Try this ...
Begin Unverified Perl

my $RandNum=SYSRAND(1,2);

 if($RandNum==1)
   {
    ADD("BlockList",1,5);
   }
 else
   {
    ADD("BlockList",6,10);
   }
End Unverified
answered Jan 11 by Paul Moon Platinum (95,550 points)
Thanks for your fast answer. I believe also that would be the way to go.

Another short question:
I got a Question named CVHI it is a select question with two answers
1: Yes and 2: No

Now next question should adapt his text if yes or no is selected.
My idea was to try it this way:

Begin Unverified Perl
    my$CVHI=GETVALUE("CVHI");
if ($CVHI=="Yes")
    {
        return "Text if yes";
else
    {
        return "Text if no"; 
    }
End Unverified %]


but this code does not work, any edits necessary?
Use ==1 instead.

And best to use a different variable name if a question already uses the same name.

You can also remove the my command and just say if GETVALUE(“CVTI”).

So change my $CVHI to my $QCVHI or some other appropriate name.
I have tried this, but it does not work.

[% Begin Unverified Perl
if GETVALUE("CVHI"==1)
{
    return "Text if yes";
}
else
{
    return "Text if no";
}
End Unverified %]
I got it. It is working - however i just looked at preview from 2-3 questions before, because i don't want to click through the whole survey - but preview always shows text if no, in total it works.
Insert an opening bracket before GETVALUE and a closing bracket before ==1.

See below ...
[% Begin Unverified Perl
if (GETVALUE("CVHI")==1)
{
    return "Text if yes";
}
else
{
    return "Text if no";
}
End Unverified %]

Ignore the preview mode for Perl script as it will show the ELSE condition script. Ensure you test it out.
...