Dear CSPro Team,
Need help on a dynamic value in a roster.
Can we use a setvalueset function for dynamic value on a single entry in a roster?
I have a roster in which one of the columns was a single choice entry. I want in each row, if the option is already chosen, then the selected option wouldn't be displayed in the next row.
Kindly please help me.
Regards,
lusia
Dynamic Value in a Roster
-
- Posts: 1806
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Dynamic Value in a Roster
You can use setvalueset on any field in your program. The important thing in a roster is that you put the code for this in onfocus, not preproc. This is because you want to dynamically create the value set regardless of whether you're moving forwards in the application or backwards. Preprocs are only executed when moving forwards, but you want to make sure that your value set is correct for each row of the roster, even if you move backwards.
If you look at the CAPI Census example, which will be here:
C:\Users\<your name>\Documents\CSPro\Examples 7.2\1 - Data Entry\CAPI Census\Household
Look at PROC HH_RELATIONSHIP to see how the value set is dynamically created in the onfocus.
If you look at the CAPI Census example, which will be here:
C:\Users\<your name>\Documents\CSPro\Examples 7.2\1 - Data Entry\CAPI Census\Household
Look at PROC HH_RELATIONSHIP to see how the value set is dynamically created in the onfocus.
Re: Dynamic Value in a Roster
Thank you for the reply.
I've checked at PROC HH_RELATIONSHIP in C:\Users\<your name>\Documents\CSPro\Examples 7.2\1 - Data Entry\CAPI Census\Household. It protected the first curocc should be Household Head.
But I want in each rows will have the rest of option that aren't be chosen in each rows before.
Or should I define the VS for each option? For example if there are 12 option, I have to make 12 VS for each option?
Regards,
lusia
I've checked at PROC HH_RELATIONSHIP in C:\Users\<your name>\Documents\CSPro\Examples 7.2\1 - Data Entry\CAPI Census\Household. It protected the first curocc should be Household Head.
But I want in each rows will have the rest of option that aren't be chosen in each rows before.
Or should I define the VS for each option? For example if there are 12 option, I have to make 12 VS for each option?
Regards,
lusia
-
- Posts: 1806
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Dynamic Value in a Roster
You can create a value set that does not contain the options previously selected. Something like this:
PROC VALUE
onfocus
array numeric vs_codes(100);
array string vs_labels(100);
numeric vs_counter = 1;
do numeric vs_value = minvalue(VALUE_VS1) while vs_value <= maxvalue(VALUE_VS1)
// check if there is a label for this value, meaning that it is a valid option
if getlabel(VALUE_VS1, vs_value) <> "" then
// make sure that this value hasn't been used
if not VALUE has vs_value then
// add it to the value set
vs_codes(vs_counter) = vs_value;
vs_labels(vs_counter) = getlabel(VALUE_VS1, vs_value);
inc(vs_counter);
endif;
endif;
enddo;
// end and set the value set
vs_codes(vs_counter) = notappl;
setvalueset(VALUE, vs_codes, vs_labels);
onfocus
array numeric vs_codes(100);
array string vs_labels(100);
numeric vs_counter = 1;
do numeric vs_value = minvalue(VALUE_VS1) while vs_value <= maxvalue(VALUE_VS1)
// check if there is a label for this value, meaning that it is a valid option
if getlabel(VALUE_VS1, vs_value) <> "" then
// make sure that this value hasn't been used
if not VALUE has vs_value then
// add it to the value set
vs_codes(vs_counter) = vs_value;
vs_labels(vs_counter) = getlabel(VALUE_VS1, vs_value);
inc(vs_counter);
endif;
endif;
enddo;
// end and set the value set
vs_codes(vs_counter) = notappl;
setvalueset(VALUE, vs_codes, vs_labels);
Re: Dynamic Value in a Roster
Dear Gregory,
I'm sorry for the very late reply.
I've just finished testing your script above.
Firstly I still got 0 for the result. But in the end, I just have to add () symbol in the second if inside the while do.
Here is the screenshot of the result of your code.
Thank you a lot for your help, Gregory.
Warm Regards,
lusia
I'm sorry for the very late reply.
I've just finished testing your script above.
Firstly I still got 0 for the result. But in the end, I just have to add () symbol in the second if inside the while do.
Code: Select all
PROC GLOBAL
array numeric vs_codes(100);
array string vs_labels(100);
PROC TEST_ROSTER_FF
PROC A_1
onfocus
numeric vs_counter = 1;
// errmsg("%d", minvalue(A_1_VS1));
// errmsg("%d", maxvalue(A_1_VS1));
do numeric vs_value = minvalue(A_1_VS1) while vs_value <= maxvalue(A_1_VS1)
// check if there is a label for this value, meaning that it is a valid option
if getlabel(A_1_VS1, vs_value) <> "" then
// errmsg("%s", getlabel(A_1_VS1, vs_value));
// make sure that this value hasn't been used
if not (A_1 has vs_value) then
// add it to the value set
vs_codes(vs_counter) = vs_value;
vs_labels(vs_counter) = getlabel(A_1_VS1, vs_value);
inc(vs_counter);
endif;
endif;
enddo;
// end and set the value set
vs_codes(vs_counter) = notappl;
setvalueset(A_1, vs_codes, vs_labels);
Warm Regards,
lusia