Question

Discussions about CSEntry
SieAIP
Posts: 24
Joined: April 7th, 2020, 5:57 pm

Question

Post by SieAIP »

Hello CSPro Users, pls I'm a new member here. Pls can you help me out on this?

I want to create a dynamic checkbox in CSPro such that only the options checked in QUESTION one will be available in Question two, the options are up to one hundred (Length = 3). Is this possible in CSPro? If yes, how can I go about it and what should I put under the logic section?
Thanks as I wait for a swift response.
khurshid.arshad
Posts: 572
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Question

Post by khurshid.arshad »

You can get "The Simple CAPI example" that comes with the CSPro installation.
Go to Tools-> Example Folder->1-Data Entry-> Simple CAPI


Please see this post as well viewtopic.php?f=1&t=3279&p=10275

Best.
a
SieAIP
Posts: 24
Joined: April 7th, 2020, 5:57 pm

Re: Question

Post by SieAIP »

Thanks khurshid.arshad, I have gone through those materials as you have directed but it could not solve my problem. let me site an example to explain my question better so that you can deal with it straight up and I'll use the template to solve my issue.

For instance;

Q1. Please tick all days you attended the event. (Options are "Day1 - Day200" with codes as below):
1 = Day1
2 = Day2
3 = Day3
. = .
. = .
. = .
200 = Day200[/color][/color]

Q2. Out of these days, tick 5 you think the event was most interesting.

Let's assume that I ticked "Day100 - Day112) in Q1. I want these to be the only options available in Q2 so I can go ahead and chose 5 from the options as demanded by Q2.

Please, how can I handle this? Specifically the Dictionary set up for this questions and the logic to compile.

I understand that check-boxes uses alphanumeric character where the length is set to be equal to the number of options. Letters can be used for this to represent all options but my case has even more than the 26 Letters of the Alphabet.
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Question

Post by Gregory Martin »

You can use checkbox characters that are greater than length 1, so you could make each code three characters (001-200) and then the field 15 characters (3 characters x 5 options). Then, to process the selections, you would have logic like this:
do numeric counter = 1 while counter <= length(CHECKBOX_FIELD) by 3

   
string this_selection = CHECKBOX_FIELD[counter:3];

    // do something with this value

enddo;
SieAIP
Posts: 24
Joined: April 7th, 2020, 5:57 pm

Re: Question (Dynamic checkboxes)

Post by SieAIP »

Thanks Mr. Martin! I have been able to set up the Checkbox correctly in the dictionary now. Please I have included a sample file here (
studyexerciseincapi.zip
Sample file (zip file) of my issues. please unzip to access all files as appropriate.
(25.28 KiB) Downloaded 355 times
), or use the link(download/file.php?mode=view&id=1459). I have reduced the options to 30 and checkbox characters to length 2 just for convenience of this demo. I have also included the logic code in there but it's not working. Can you please work on the file and give me the right logic code?

Thanks in waiting sir!
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Question

Post by Gregory Martin »

You need to loop through every option and then add it to a dynamic value set:
PROC Q2

onfocus

    // set up the value set showing only the options from Q1
   
valueset string vs;

   
do numeric counter = 1 while counter <= Q1_VS1.length()

       
if ischecked(Q1_VS1.codes(counter), Q1) then
           
vs.add(Q1_VS1.labels(counter), Q1_VS1.codes(counter));
       
endif;

   
enddo;

   
setvalueset(Q2, vs);

postproc

    if length
(strip(Q2)) = 0 then
        errmsg
("You must choose at least one of the days you attended the event and felt it was interesting.");
       
reenter;
   
endif;
If you are not using CSPro 7.4, you will not have the ischecked function. You can use this instead:
if pos(Q1_VS1.codes(counter), Q1) % 2 = 1 then
SieAIP
Posts: 24
Joined: April 7th, 2020, 5:57 pm

Re: Question (Dynamic checkboxes)

Post by SieAIP »

Thanks loads Mr. Gregory Martin!
You have perfectly solved my problem now.

Now the returned result is a long boring string of numbers which exporting the data to external software may make no or little sense especially when many options are checked. Is there something I can do to help me export it out to excel or SPSS more meaning fully?
Thanks always!

SIDE ATTRACTION: Can you also check the alternative code you gave in case I'm using CSPro version lower than 7.4?
This alternative code (if pos(Q1_VS1.codes(counter), Q1) % 2 = 1 then) is partially working. For instance, if you checked "01", "02", "10", and "20", Q2 will only bring options "01" and "02" leaving "10" and "20" behind. I think the system is taking it to be duplicates since the "01" and "10" etc contains same values (a zero and a one).
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Question

Post by Gregory Martin »

You're right that the code had a problem. That's why the IsChecked function is much more useful that Pos. We posted a blog about that yesterday:

https://www.csprousers.org/posts/2020-0 ... f-pos.html

Anyway, here's a way to do it in 7.3:
    // set up the value set showing only the options from Q1
   
valueset string vs;

   
do numeric counter = 1 while counter <= length(Q1) by 2

       
string this_code = Q1[counter:2];

       
if this_code <> "" then
           
vs.add(getlabel(Q1, this_code), this_code);
       
endif;

   
enddo;

   
setvalueset(Q2, vs);
For exporting, look at page 85 of this: https://www.csprousers.org/resources/CS ... rkshop.pdf
SieAIP
Posts: 24
Joined: April 7th, 2020, 5:57 pm

Re: Question

Post by SieAIP »

Okay! Thanks loads Mr. Gregory Martin, I really do appreciate your timely and swift responses.
SieAIP
Posts: 24
Joined: April 7th, 2020, 5:57 pm

Re: Question (Skips from Checkboxes)

Post by SieAIP »

Hello Mr. Gregory Martin and other CSPro users that can help me out!

Please, can you help me program a skip from the checkbox example file (studyExercise) attached earlier to this question?

I want a navigation to Q3 if DAY30 (code is 30) was checked either alone or with other options and a skip to Q4 if DAY30 was not checked.

Please, help me with how to program the logic.

Thanks!
Post Reply