Dynamic Value Sets from Checkboxes
Dynamic Value Sets from Checkboxes
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);
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);
Re: Dynamic Value Sets from Checkboxes
The error you are getting is because you have declared the same variable twice.
You have:
and then two lines later you declare the same variable again:
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.
You have:
Code: Select all
string INFORMATIONCheckboxCodes = "12345678910111217";
Code: Select all
string INFORMATIONCheckboxCodes = INFORMATIONCheckboxCodes[INFORMATIONNumericCode:1];
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.
Re: Dynamic Value Sets from Checkboxes
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
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
Re: Dynamic Value Sets from Checkboxes
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";
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";
Re: Dynamic Value Sets from Checkboxes
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? 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.
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? 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.
Re: Dynamic Value Sets from Checkboxes
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?
-
- Posts: 580
- Joined: July 9th, 2012, 11:32 am
- Location: Islamabad, Pakistan
Re: Dynamic Value Sets from Checkboxes
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.
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
Re: Dynamic Value Sets from Checkboxes
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.
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.
-
- Posts: 580
- Joined: July 9th, 2012, 11:32 am
- Location: Islamabad, Pakistan
Re: Dynamic Value Sets from Checkboxes
Dear
Please see attached file. In this case, you can see the option "Yes" against each selection.
Best.
a.
Please see attached file. In this case, you can see the option "Yes" against each selection.
Best.
a.
-
- Posts: 580
- Joined: July 9th, 2012, 11:32 am
- Location: Islamabad, Pakistan
Re: Dynamic Value Sets from Checkboxes
Sorry. The attachment was missing in my last post.
a.
a.
- Attachments
-
- CHECK ALL THAT APPLIES.rar
- (9.81 KiB) Downloaded 453 times