Auto tick in Check Box (Multiple Answer)

Discussions about CSEntry
Post Reply
pradhanra01
Posts: 38
Joined: August 27th, 2017, 2:43 am

Auto tick in Check Box (Multiple Answer)

Post by pradhanra01 »

Hi All,

I am facing a problem to implement auto tick in check box question based on previous question. For Example :
Q1. Insurance Companies interacted in the last 12 months... (Multiple Answer)
MetLife - 1
General Life - 2
Neco Insurance -3
Surya Life - 4
LIC - 5

Q2. Insurance Companies interacted in the last 24 months... (Multiple Answer) ...
MetLife - 1
General Life - 2
Neco Insurance -3
Surya Life - 4
LIC - 5

After Asking Q1... While asking Q2... there should be auto checked responses which has been already selected in Q1...
Could you please suggest me how can I implement my requirement in CSPro Data Entry ?

Regards,
Ramesh
justinlakier
Posts: 152
Joined: November 21st, 2022, 4:41 pm

Re: Auto tick in Check Box (Multiple Answer)

Post by justinlakier »

Hi Ramesh,

If you include a line in the preproc of Q2 saying "Q2=Q1", that would auto-tick all answers from Q1. However this would overwrite what you entered in Q2 every time you reentered it. Instead, I would recommend using something like this.
PROC Q2
preproc
numeric
i=1;
string halfDistance = "";
do while i<=length(Q1);
    string char = Q1[i:1];
    if pos(char, $)=0 and not char=" " then
       
halfDistance = concat(halfDistance, char);
    endif;
    i=i+1;
enddo;
$=concat(halfDistance, $);
This method checks if each character from Q1 is already in Q2, and appends those characters which need to be auto-ticked in Q2 onto a string. It then appends that string onto Q2. This way there are not character duplicates and the characters in Q2 are not overwritten when it is reentered. This assumes that Q1 and Q2 have the same valuesets, and that the values in Q1 plus the current values in Q2 do not exceed the length of Q2- otherwise the current values of Q2 will be rewritten. You may want to order the result for clarity, however the results of a checkbox check if a character is present, not for what position that character is in, so it should not make a practical difference.

Hope this helps,
Justin
Post Reply