Page 1 of 1
Dynamically updating value set items
Posted: April 2nd, 2014, 6:03 am
by zwan
Hello CSPro Users,
I hope you are all doing ok and happy with the Android news

I have a problem with a scenario: I want to be able to dynamically update value set items:
using answers entered by users in a question as value set items for following questions.
My guess is that, I will have to use Logic to alter data dictionary: Is that possible?
Re: Dynamically updating value set items
Posted: April 2nd, 2014, 1:12 pm
by Gregory Martin
It is possible. You have to use the setvalueset function to do this. If you look at the Metro Survey application included with the Android application you can see an example of how this is done:
http://www.csprousers.org/beta/MetroSurvey.7z
Re: Dynamically updating value set items
Posted: April 2nd, 2014, 6:31 pm
by zwan
Thanks.
Sounds like what I am looking for but I am not sure I understand how this thing works.
The stations have their own dictionary (Stations.dcf) and data file (metro-survey-wmataStations.dat) but how do you update the data?
What's the purpose of the Metro Survey.ent.wrk.dcf dictionary?
I don't understand how the createStationValueset(colorCode) works.
Thank you
Re: Dynamically updating value set items
Posted: April 3rd, 2014, 10:27 am
by Gregory Martin
The metro survey application is a more complicated program, so here is a more basic one. See attached, and the following code for how to create a dynamic value set based on selections made in a check box:
PROC GLOBAL
array alpha (20) vsLabels(50);
array vsCodes(50);
numeric ctr;
PROC FAVORITE_MEAT
preproc
do ctr = 1 while ctr <= length(strip(MEATS_CONSUMED))
// ctr - 1 because the dynamic value set begins at position 0, not 1
vsLabels(ctr - 1) = getlabel(MEATS_CONSUMED BY code MEATS_CONSUMED[ctr:1]);
vsCodes(ctr - 1) = ctr;
enddo;
vsCodes(ctr - 1) = notappl; // end the dynamic value set
setvalueset(FAVORITE_MEAT,vsCodes,vsLabels);
setcapturetype(FAVORITE_MEAT,1); // display this as a radio button
postproc
errmsg("Your favorite meat is: %s",getlabel(MEATS_CONSUMED BY code MEATS_CONSUMED[FAVORITE_MEAT:1]));
Re: Dynamically updating value set items
Posted: April 4th, 2014, 12:07 pm
by zwan
Thanks Greg!
I see that this is not as easy as I expected it to be.
I will give it a try and get back to you.