setvalueSet, extracting from multiple choice question

Discussions about CSEntry
yanina
Posts: 60
Joined: October 31st, 2016, 9:37 am

Re: setvalueSet, extracting from multiple choice question

Post by yanina »

Hi Josh

On Q1X how to prevent value 14 get together with others value.

I have tried this logic but get error on compiling :

Huge thanks for your help.

Yanin

Code: Select all

if curocc()>=2 and $ =  14 then 
errmsg("You can not Enter this value get mixed with others value"); 
reenter;
endif;

Code: Select all

if pos("0123456789",$)> 1 and pos("14",$)> 1
then errmsg("You can not Enter this value get mixed with others value"); 
reenter;endif;
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: setvalueSet, extracting from multiple choice question

Post by josh »

Again, you need to use the isChecked function to see if 14 is checked and you can check the length of the field to see if it is greater than 2 digits to know if more than field is checked:

if isChecked("14", $) and length(strip($)) > 2 then
    
errmsg("You can not Enter this value get mixed with others value");
    
reenter;
endif;
Laedry
Posts: 5
Joined: October 12th, 2016, 5:43 am

Re: setvalueSet, extracting from multiple choice question

Post by Laedry »

josh wrote:Welcome to the forum. For a bit of background on how to interpret checkboxes using the pos function you may want to see this post (http://csprousers.org/forum/viewtopic.p ... 9&start=10).

To use setvalueset to implement the crops questions that you describe you will need to declare two string arrays in the proc global. With most setvalueset examples you use a numeric array of codes and a string array of labels but since you are dealing with checkboxes your codes array will be a string array too.

In the onfocus of Q2 you will need to loop through each of the possible crop codes (1 through 6) and check if the corresponding crop was chosen in Q1. If it was NOT chosen then you add it to the codes and labels arrays. After the loop you call setvalueset on Q2 with the codes and labels arrays. What makes this a bit tricky is that since Q1 and Q2 are alphanumeric variables, the codes are not the numeric values 1 through 6. They are the string equivalents: "1", "2", ... "6". So in your loop you will need to convert from the number to the equivalent string. You can do this with either the maketext function or the edit function. Once you have the codes as strings then you can use pos to determine if the code was selected in Q1. If it is selected then you add it to the array of codes and labels.

Here is how I would write the loop:
PROC Q2
onfocus
// Setvalueset for Q2 to crops not selected in Q1

// Numeric crop code (1-6)
numeric codeNumeric;

// Next slot in codes/labels array to insert into
numeric nextEntry = 1;

// Loop through each crop
do codeNumeric = 1 while codeNumeric <= 6

    
// String version of crop code ("1" instead of 1)
    string codeString = edit("9", codeNumeric);
    
    
// Check if crop was selected in Q1
    if pos(codeString, Q1) = 0 then
        
// Not selected in Q1, add to value set for Q2
        codes(nextEntry) = codeString;
        labels(nextEntry) =
getlabel(Q1, codeString);
        
        
// Filled in last slot, point to next empty slot
        nextEntry = nextEntry + 1;
    
endif;
enddo;
// Mark end of new value set
codes(nextEntry) = "";

// Set value set for Q2
setvalueset(Q2, codes, labels);
For Q3 the logic would be similar except that instead of testing if the code was not selected in Q1 you would check to see if it was selected in either Q1 or Q3.

You should also decide how to handle the case where all the crops are selected in Q1 - do you skip Q2? Same thing if nothing was selected in either Q1 or Q2 - do you skip Q3?

Mr Josh, Have you an example for this issue
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: setvalueSet, extracting from multiple choice question

Post by josh »

Not for this particular issue but there are some examples of using checkboxes with dynamic value sets here: http://teleyah.com/cspro/SouthAfricaOct ... rcises.zip

You will need CSPro 7 beta to open the files.
Laedry
Posts: 5
Joined: October 12th, 2016, 5:43 am

Re: setvalueSet, extracting from multiple choice question

Post by Laedry »

josh wrote:Not for this particular issue but there are some examples of using checkboxes with dynamic value sets here: http://teleyah.com/cspro/SouthAfricaOct ... rcises.zip

You will need CSPro 7 beta to open the files.
A good and better example, How can i filtered Variable Multiple answer (Check Box) From Single Variable (Radio Bottom)
pcpak
Posts: 19
Joined: September 8th, 2016, 3:45 am

Re: setvalueSet, extracting from multiple choice question

Post by pcpak »

Dear Josh, I am trying to validate values based on a previous question. For example, I have a question where we have asked name of the district and there are couple of districts. In the later question we are asking name of tehsil within the selected district (and there could be more than one tehsils in a district). What I want is to validate only those tehsils for a case in which a district is selected in the previous question.
Would appreciate if you could please write the code for me.
many thanks!
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: setvalueSet, extracting from multiple choice question

Post by josh »

Next time please post a new question instead of adding to a really old thread that has already been answered.

There is an example like this in the CSPro examples folder that uses a lookup file to validate districts within provinces. In CSPro 6.3 you can find it in C:\Program Files (x86)\CSPro 6.3\Examples\1 - Data Entry\Lookup Files. In CSPro 7 beta look in Documents\cspro\Examples 7.0\1 - Data Entry\Lookup Files. Another example can be found at http://teleyah.com/cspro/DCJune2015/05- ... -entry.pdf
pcpak
Posts: 19
Joined: September 8th, 2016, 3:45 am

Re: setvalueSet, extracting from multiple choice question

Post by pcpak »

I am sorry Josh for posting it within the old thread. I thought my question is related to this, so I did but I will be careful in future.

Thank you for your reply. I did try from the example files as you pointed out but somehow I could not make it to work. When I run the application it displays couple of errors, primarily related to declaration of names etc. I have also edited the lookup.dat file in the notepad but no success. I would greatly appreciate if you could please write it down for me. I want to validate list of tehsils within a district. Please also let me know how to fill the lookup.dat file.

many thanks in advance!
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: setvalueSet, extracting from multiple choice question

Post by josh »

Why don't you post what you have done and we can take a look at the errors that you are getting. Also you should use the Excel2CSPro tool to create teh lookup file rather than editing it in notepad. It will be less error prone.
pcpak
Posts: 19
Joined: September 8th, 2016, 3:45 am

Re: setvalueSet, extracting from multiple choice question

Post by pcpak »

Thanks for the reply Josh.

Here is the screen shot of errors.

Thanks for your help. I am so grateful.

B2 is a variable of district while B4 is a variable for Tehsils
Attachments
Untitled.png
Untitled.png (25.52 KiB) Viewed 6902 times
Post Reply