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", $) andlength(strip($)) > 2then errmsg("You can not Enter this value get mixed with others value"); reenter; endif;
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 = 1while codeNumeric <= 6
// String version of crop code ("1" instead of 1) string codeString = edit("9", codeNumeric);
// Check if crop was selected in Q1 ifpos(codeString, Q1) = 0then // 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?
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!
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
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.
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.