Dynamic Value Sets from Checkboxes

Discussions about creating CAPI applications to run on Android devices
Forum rules
New release: CSPro 8.0
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Dynamic Value Sets from Checkboxes

Post by gbos »

Hello CSPRO community, I want to set checkbox for my survey for a variable with value sets ranging from 1 to 13. Attached is the survey for your perusal and help.
I was able to do the following coding but still getting error:

[ERROR: Cannot create alpha variable - symbol name already exists near line 12 in INFORMATION_TOPICS procedure] I cann't seem to figure out what might be wrong. The coding is as follows:=

PROC INFORMATION_TOPICS

onfocus

// Create value set from items selected in INFORMATION TOPICS
numeric nextEntry = 1;
// Used to translate from checkbox (alpha codes) to numeric codes
string INFORMATIONCheckboxCodes = "12345678910111217";
// Loop through the numeric codes 1-13 and each selected
// to value set
do numeric INFORMATIONNumericCode = 1 while INFORMATIONNumericCode <= 17
// Convert the numeric code to the checkbox alpha code
// by looking it up in the array.
string INFORMATIONCheckboxCodes = INFORMATIONCheckboxCodes[INFORMATIONNumericCode:1];
// Check if the INFORMATION TOPIC is selected in the checkbox field
if pos(INFORMATIONCheckboxCodes, S4Q7) > 0 then
// INFORMATION TOPIC is selected. Add it to the value set.
codes(nextEntry) = INFORMATIONNumericCode;
labels(nextEntry) = getlabel(INFORMATION_TOPICS_VS1, INFORMATIONNumericCode);
nextEntry = nextEntry + 1;
endif;
enddo;


// Mark end of value set
codes(nextEntry) = notappl;
// Modify value set
setvalueset(INFORMATION_TOPICS, codes, labels);
CHECK ALL THAT APPLIES.zip
(4.25 KiB) Downloaded 364 times
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Dynamic Value Sets from Checkboxes

Post by josh »

The error you are getting is because you have declared the same variable twice.

You have:

Code: Select all

string INFORMATIONCheckboxCodes = "12345678910111217";
and then two lines later you declare the same variable again:

Code: Select all

string INFORMATIONCheckboxCodes = INFORMATIONCheckboxCodes[INFORMATIONNumericCode:1];
You can only declare the variable once.

There is however a bigger problem with what you are trying to do. The approach you are using to convert the checkboxes does not support two digit codes in the value set. It was meant to be used with single digit codes which is why you usually see other examples using value sets with codes "A", "B", "C"... Using letters instead of numbers gives you 26 possible values (or more if you use capital letters and symbols) with a single digit. You can either switch your value set to use letters or you can copy the isChecked function from this post:

http://www.csprousers.org/forum/viewtop ... =isChecked

The isChecked function can handle two digit codes like yours.
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Dynamic Value Sets from Checkboxes

Post by gbos »

Dear Josh,
Many thanks for your support and understanding. Thanks to your solution and effort the first problem is now solved. However, am still confused about the second problem: Dynamic value sets from checkboxes. I tried following your suggestion in the link you suggested but I ended up more confused. Attached is my program. As suggested I copied

/ Determine if code was checked in checkbox field checkboxItem.
// Supports any multiple digit codes. Steps through
// the field by the length of the code and checks for the
// presence of code in each position. For 1 digit codes checks
// every position (just like pos), for 2 digit codes checks positions
// 1,3,5... and for 3 digit codes checks 1,4,7... This avoids
// false positives that you would get using pos in a case like
// pos("01", "1011").
function isChecked(string code, string checkboxItem)
numeric i;

// Step by length of code so that we don't look at substrings
// that are not aligned to code boundary.
numeric stepSize = length(code);

// Assume not checked, this will be return value if we
// find nothing.
isChecked = 0;

// Loop through checkboxField
do i = 1 while i <= length(checkboxItem) by stepSize

// Check substring of length stepSize at position i
if code = checkboxItem[i:stepSize] then
// Found a match, set return value to true and exit loop
isChecked = 1;
break;
endif;
enddo;
end;

and copied

PROC S4Q7


numeric i;
string alphabet = "12345678910111217";

do i = 1 while i <= 16
string codeString = edit("99", i);
if isChecked(codeString, alphabet) <> 0 then
S4Q7(i) = 1;
else
S4Q7(i) = 0;
endif;
enddo;


and compiled successfully. But I am not just getting Checkboxes. I assume am definitely missing some critical steps. Please, your urgent assistance will be highly appreciated. Attached is the test survey
CHECK ALL THAT APPLIES.zip
(7.57 KiB) Downloaded 318 times
sah
Posts: 97
Joined: May 28th, 2015, 3:16 pm

Re: Dynamic Value Sets from Checkboxes

Post by sah »

hi gbos,
Kindly check your alpha string. for two digits, use the rule of alpha so for instance you can use a b c d .....numeric i;
string alphabet = "123456789ABCDEFG";
gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Dynamic Value Sets from Checkboxes

Post by gbos »

Dear Josh,

Thanks for the suggestion. However, the list came out as a list instead of a checkbox, I decided to change the target variable S4Q7 from Numeric to Alpha and increase the length to 16. Is that correct? How should the target variable s4q7 be defined in the dictionary? :roll: Having done that the program failed to compile and gave error instead. The error message is given below as:

ERROR: Invalid character expression near line 9 in S4Q7 procedure

Another question?? How can Other Specify which is the last option be handled with this solution??

Attached is both the screen captured and the sample application.
Screen capture.docx
(132.37 KiB) Downloaded 333 times
CHECK ALL THAT APPLIES.zip
(7.59 KiB) Downloaded 341 times
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Dynamic Value Sets from Checkboxes

Post by josh »

I don't understand what you are trying to do. Based on your initial question I thought you wanted to make a dynamic value set (a list) out of the items that are checked in a check box field of a previous question. Looking at your example program I'm not sure anymore. SQ47 is a checkbox field so it is alpha. Why are you trying to assign it a numeric value?
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Dynamic Value Sets from Checkboxes

Post by khurshid.arshad »

Dear

Please assigne 01,02,03 etc in value set in S4Q7 instead 1,2,3 and after that you can see your checkbox option in entry mode.

For others please see this code:
Best,
a.

Code: Select all

	If length(strip($))=0 then

		errmsg ("Invalid entry");
		reenter;

	else
		If Poschar("17", $)>0 then

		else
			skip to INFORMATION_TOPICS;
		endif;

	endif

gbos
Posts: 51
Joined: June 18th, 2015, 7:49 pm

Re: Dynamic Value Sets from Checkboxes

Post by gbos »

Dear Kurshid,

Thanks for your intervention. Yes with your suggestion I was able to get Check Boxes. However, having tested them after trial entry and export into SPSS, I couldn't Yes and now. All the variable, all 13 of them came blank. Am still confused about this and no knowing how to proceed.
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Dynamic Value Sets from Checkboxes

Post by khurshid.arshad »

Dear
Please see attached file. In this case, you can see the option "Yes" against each selection.

Best.
a.
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Dynamic Value Sets from Checkboxes

Post by khurshid.arshad »

Sorry. The attachment was missing in my last post.
a.
Attachments
CHECK ALL THAT APPLIES.rar
(9.81 KiB) Downloaded 363 times
Post Reply