Validation issue in Checkbox

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
prabhustat
Posts: 72
Joined: March 17th, 2012, 10:46 am

Validation issue in Checkbox

Post by prabhustat »

Dear team,

I have issue in validation checkbox, when I adopt the below conditions. when I select other options and refused the validation works perfectly , but when select only refused -88 or No other sourced -12 then I am not move to next variables.

PROC Q19
if not checkboxHasSelection(Q19) then
errmsg("Please choose at least one option");
reenter;
endif;

numeric choseprimaryoccup = poschar("0102030405060708091011", Q19) > 0;
numeric choserefuesed2 = ischecked("88", Q19);
if choseprimaryoccup and choserefuesed2 then
errmsg("'Refused' If refused, other options cannot be select.");
reenter;
endif;

numeric choseprimaryoccup1 = poschar("0102030405060708091011", Q19) > 0;
numeric choserefuesed3 = ischecked("12", Q19);
if choseprimaryoccup1 and choserefuesed3 then
errmsg("'No other source' If No other source of income, other options cannot be select.");
reenter;

endif;

Thanks,
PP
sherrell
Posts: 397
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: Validation issue in Checkbox

Post by sherrell »

Neither of your test conditions allow 88 or 12 to be entered on their own. Both conditions require that something be entered as a primary occupation. So, you'd have to change it to allow that to happen. For example, start your logic with:

Code: Select all

if length (strip($))=2 and strip($) in "12","88" then
  errmsg("this works");
else
// do the rest of your pgm
Also, I'm assuming you've created a value set for Q19 that lists the individual 01, 02, etc values? For the pochar function as you're attempting to use it doesn't work as you're intending/you think. It's not validating 2 characters at a time, but only a single character from the string provided.

You've got: numeric choseprimaryoccup = poschar("0102030405060708091011", $) > 0;
Change it to: numeric choseprimaryoccup = poschar("0123456789", $) > 0;

and you'll see it also "works". Because it's testing true on the presence of a 1 or 2 or 3 in isolation, not the two-char grouping. For that to happen, you'd have to write logic to loop through the string entered, two chars at a time. Use the pos function in that situation.

https://www.csprousers.org/help/CSPro/pos_function.html
https://www.csprousers.org/help/CSPro/p ... ction.html

Sherrell
prabhustat
Posts: 72
Joined: March 17th, 2012, 10:46 am

Re: Validation issue in Checkbox

Post by prabhustat »

Thanks, let me try.
Post Reply