Value Set

Discussions about creating CAPI applications to run on Android devices
Forum rules
New release: CSPro 8.0
Post Reply
clyde16
Posts: 1
Joined: February 11th, 2020, 5:04 pm

Value Set

Post by clyde16 »

Hi,
I want to create a multiple choice question with dynamic values, depending on conditions compared to previous questions
when I put a single choice question it works but multiple choice it does not work!

here is what i do:

PROC OPERATOR

preproc
      valueset OPERATOR_valueset;


          if pos ("A", Q1)> 0 then
              OPERATOR_valueset.add ("khati", 1);
          endif;
    

      setvalueset (OPERATOR, OPERATOR_valueset);
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Value Set

Post by aaronw »

Typically I see users wanting to create a dynamic value set from response of a check box. However, you want to create a dynamic value set for a check box.

If your approach is only working for a single choice then the issue is probably that the length of the check box variable is set to 1. The length of a check box variable must be equal to the number of allowable response. However, this has two issues. There isn't a programmatic way to set a variable's length. Even if there was this will muck up data collection, because CSPro partly organizes its data by length.

My approach would be to create a dictionary variable that allows for the maximum number of responses. If you have less responses code the extra ones, so they can be ignored. For example, let's say your check box allows for 5 responses. The valid responses could be "ABCDE" and "UVWXZ" could be ignored.
btri Arjun
Posts: 37
Joined: August 17th, 2018, 6:09 am

Re: Value Set

Post by btri Arjun »

Dear all,

I want to make a dynamic valueset form the previous multiple questions. If Q15 is the question for dynamic valueset then, If Q5 = 1 then Q15 = Cancer, If Q7 = 1 then Q15 = TB, if Q9 = 1 then Q15 = Thyroid …. I tried to make a valueset like this;

valueset diseases;
if Q5 = 1 then diseases ("Cancer”,1);
elseif Q7 = 1 then diseases ("TB",2);
elseif Q9 = 1 then diseases ("Thyroid",3);
endif;
setvalueset(Q15, diseases);
but this shows the all values even if Q5 = 2 or Q7 = 2 ……. How is it possible?

Thank you
Arjun
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Value Set

Post by josh »

You need to use diseases.add("Cancer", 1) instead of diseases("Cancer", 1).
btri Arjun
Posts: 37
Joined: August 17th, 2018, 6:09 am

Re: Value Set

Post by btri Arjun »

Dear josh,

Thanks for your response, It worked. But when I return back the previous question and go forward to the Q15, than the values added each times in the field again (see screenshot). How can I avoid this problem.

Thank you.

Arjun
Attachments
Q15.png
Q15.png (8.13 KiB) Viewed 4416 times
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Value Set

Post by josh »

To make sure it works when you go back you should put your logic in the onfocus rather than in the preproc. Also make sure that the your valueset variable is local (declared inside the proc) or if it is declared globally then remove the old values by calling valueset.clear() by before adding in the new ones.
btri Arjun
Posts: 37
Joined: August 17th, 2018, 6:09 am

Re: Value Set

Post by btri Arjun »

Dear josh,

Thank for help. It worked well.
josh wrote: February 25th, 2020, 11:30 pmvalueset.clear()
Arjun
Post Reply