Can value sets be changed by answers to prior questions?

Discussions about CSEntry
Post Reply
wimneel
Posts: 90
Joined: May 6th, 2017, 5:31 am

Can value sets be changed by answers to prior questions?

Post by wimneel »

Hi everybody,

I have some experience developing applications in CSPro, but am not a crack. I am using version 6.3.
My questionnaire has three questions, one that asks "what is your first choice" (from a list of about 20 options), a second and a third one that ask for the second and third choice. Those questions use radio buttons as capture type.
Is it possible to, after the first question has been answered, remove the answer from the value set of the second and third question? Etc.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Can value sets be changed by answers to prior questions?

Post by josh »

Yes, this is a technique called dynamic value sets. You use the function setvalueset() to modify your value set from logic. See http://teleyah.com/cspro/DCJune2015/04-CAPI/04-CAPI.pdf for a description. You can also look at the simplecapi example in the CSPro examples folder as it does this for the language question. There are also dozens of posts on this forum on the subject. Search for setvalueset.
wimneel
Posts: 90
Joined: May 6th, 2017, 5:31 am

Re: Can value sets be changed by answers to prior questions?

Post by wimneel »

Thank you very much, Josh, for your quick response!
wimneel
Posts: 90
Joined: May 6th, 2017, 5:31 am

Re: Can value sets be changed by answers to prior questions?

Post by wimneel »

One follow-up question.
Is there a function that returns the value codes and labels from a value set (e.g into an array)?
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Can value sets be changed by answers to prior questions?

Post by josh »

Unfortunately there is not. If you know the codes you can retrieve the labels using the function getlabel() which gets the label for a particular code. Even if you don't know the values but you know the range, you can loop through the range and call getlabel() on each possible value ignoring the ones with blank labels. Something like:
array codes(10);
array string labels(10);

numeric numCodes = 0;

do numeric i = 1 while i <= 9
  
string label = getlabel(MYVALUESET_VS, i);
  
if label <> "" then
    numCodes = numCodes +
1;
    codes(numCodes) = i;
    labels(numCodes) = label;
  
endif;
enddo;
wimneel
Posts: 90
Joined: May 6th, 2017, 5:31 am

Re: Can value sets be changed by answers to prior questions?

Post by wimneel »

Thank you very much, Josh. That was very helpful!
Post Reply