Have an idea?

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

Showing the value of a text variable using Perl

I have a question where the text value from a previous questions needs to be displayed within the text on another question.  The Perl code is working fine for the first two responses (Mother, Grandmother), however I can't figure out the correct syntax to show the text value of cprif1_aunt.

Thanks in advance!

Is [% Begin Unverified Perl
if(VALUE("cprif1_r1")==1){
return " your Mother";}
if(VALUE("cprif1_r1")==2){
return "your Grandmother";}
if(VALUE("cprif1_r1")==3){
return ('cprif1_aunt');}
End Unverified %]
here in the Thiwáhe Glúwašʼakapi program with you?
asked Oct 30, 2014 by RhondaDick (180 points)

1 Answer

0 votes
You have the return value for "cprif1_r1=3" as "cprif1_aunt"? Should this be "your Aunt"?

If you are trying to insert a variable's value for the 3rd condition, use the value command like VALUE("Q1") after the return command.
answered Oct 30, 2014 by Paul Moon Platinum (63,820 points)
Maybe I didn't explain it correctly.  The project team wants to use "your Mother" and "your Grandmother" for the first two responses.  These work perfectly.  However for the Aunt response they want to use the person's name which is entered into a separate variable (which I just created a bit differently) and is "cprifaunt1_r1."  

Here's my current code:

if(VALUE("cprif1_r1")==3){
return ("cprifaunt1_r1");}


Using this code, I get:
Is cprifaunt1_r1 here in the .........?  I guess it does this because it considers anything between the quotes to be "text" and not a variable name.

I've also tried (cprifaunt1_r1), ('cprifaunt1_r1'), ([%cprifaunt1_r1%], but I get either the variable name and not the value or I get an error message.
Try ...
if (VALUE("cprif1_r1")==3)
{
 return VALUE("cprifaunt1_r1");
}

Be sure to take the case into account with your variable name. Perl is case sensitive so a slight mishap will prevent it from working.
That's it!  Thank you so much!
...