Dynamic Value in a Roster

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
lusia
Posts: 49
Joined: March 28th, 2018, 4:56 am

Dynamic Value in a Roster

Post by lusia »

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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Dynamic Value in a Roster

Post by Gregory Martin »

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.
lusia
Posts: 49
Joined: March 28th, 2018, 4:56 am

Re: Dynamic Value in a Roster

Post by lusia »

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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Dynamic Value in a Roster

Post by Gregory Martin »

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);
lusia
Posts: 49
Joined: March 28th, 2018, 4:56 am

Re: Dynamic Value in a Roster

Post by lusia »

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.

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);
Here is the screenshot of the result of your code.
dynamic_value_roster.jpg
dynamic_value_roster.jpg (64.87 KiB) Viewed 3378 times
Thank you a lot for your help, Gregory.

Warm Regards,
lusia
Post Reply