Hi - I am using fields with check boxes throughout my application, and many of these have an "interviewee doesn't know" option. To help keep the data clean, when the "interviewee doesn't know" option is selected I want it to be the only answer, and that any other answers which may contradict this are deleted from the check box field. I'm trying to set this in the postproc of the field, but without success. Say that my "interviewee doesn't know option" is coded as G, my logic is:-
PROC Q209
postproc
if $ has "G" then
$="G"
endif;
It compiles OK, but doesn't work.
Where am I going wrong?
Many thanks
Keith
check boxes - using "answer not given" option
-
- Posts: 56
- Joined: March 23rd, 2014, 9:30 am
-
- Posts: 56
- Joined: March 23rd, 2014, 9:30 am
Re: check boxes - using "answer not given" option
I've thought more about this, and realise that it would be better to have an error message to highlight contradictory answers rather than automatically alter the data. So, say for my question "What problems may need medical treatment?" and the check box answers are:-
A severe headache
B blurred vision
C high blood pressure
D no answer given
I would want to have a postproc error message if D and anything else was checked. I've been experimenting with the code i.e.:-
if $ has D and $ has A:C then
errmsg ("Contradictory answer")
endif;
But this isn't functioning correctly, and I realise that I need something to denote that the letters are part of a string. I've tried wildcard character (*) but no luck.
Any help very much appreciated.
Thanks
Keith
A severe headache
B blurred vision
C high blood pressure
D no answer given
I would want to have a postproc error message if D and anything else was checked. I've been experimenting with the code i.e.:-
if $ has D and $ has A:C then
errmsg ("Contradictory answer")
endif;
But this isn't functioning correctly, and I realise that I need something to denote that the letters are part of a string. I've tried wildcard character (*) but no luck.
Any help very much appreciated.
Thanks
Keith
Re: check boxes - using "answer not given" option
Use 'POS' function to search for "D" in the response checked.
X=POS("D",$);
IF x<>0 THEN
$="D";
ENDIF;
X=POS("D",$);
IF x<>0 THEN
$="D";
ENDIF;
-
- Posts: 56
- Joined: March 23rd, 2014, 9:30 am
Re: check boxes - using "answer not given" option
Thanks! This works perfectly. Here's my code to capture 1) missed entry for a checkbox question and 2) a contradictory answer (where "G" represents 'no answer given' and so should always be the only response, in position 1):-
PROC Q209
postproc
if $="" then
errmsg("Please tick at least one box for this question");
reenter;
else
numeric x;
x=pos("G",$);
if x<>1 then
errmsg ("Contradictory answer, please review");
reenter;
endif;
endif;
PROC Q209
postproc
if $="" then
errmsg("Please tick at least one box for this question");
reenter;
else
numeric x;
x=pos("G",$);
if x<>1 then
errmsg ("Contradictory answer, please review");
reenter;
endif;
endif;
-
- Posts: 1812
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: check boxes - using "answer not given" option
As another example, here is some code that I've used to exhaustively check that the checkbox options are correct:
if length(strip(C_A04_CHILD_CARE_CHOOSE)) = 0 then
errmsg("You must select at least one option.");
reenter;
endif;
// the following check wouldn't be necessary on Android, where the user can't key in the checkbox values themselves
do itr = 1 while itr <= length(C_A04_CHILD_CARE_CHOOSE)
if not poschar(C_A04_CHILD_CARE_CHOOSE[itr:1],"ABC ") then
errmsg("The selected option, %s, is invalid.",C_A04_CHILD_CARE_CHOOSE[itr:1]);
reenter;
endif;
enddo;
if pos("C",C_A04_CHILD_CARE_CHOOSE) > 0 and length(strip(C_A04_CHILD_CARE_CHOOSE)) <> 1 then
errmsg("You cannot select C along with another option.");
reenter;
endif;
errmsg("You must select at least one option.");
reenter;
endif;
// the following check wouldn't be necessary on Android, where the user can't key in the checkbox values themselves
do itr = 1 while itr <= length(C_A04_CHILD_CARE_CHOOSE)
if not poschar(C_A04_CHILD_CARE_CHOOSE[itr:1],"ABC ") then
errmsg("The selected option, %s, is invalid.",C_A04_CHILD_CARE_CHOOSE[itr:1]);
reenter;
endif;
enddo;
if pos("C",C_A04_CHILD_CARE_CHOOSE) > 0 and length(strip(C_A04_CHILD_CARE_CHOOSE)) <> 1 then
errmsg("You cannot select C along with another option.");
reenter;
endif;