Prefill roster columns from external files

Discussions about CSEntry
Post Reply
blumski
Posts: 37
Joined: May 7th, 2018, 7:02 am

Prefill roster columns from external files

Post by blumski »

Hello dear users,

Would you please help me ?

I want to prefill two columns of a roster based on values from an external file (from excel to cspro).
For example, if the first province is choosen (PROVINCE=1), prefill school code and school name of the choosen province.

I read this but did not help : viewtopic.php?p=13621&hilit=prefill#p13621
The attached file contains a sample app.

I need your help
Attachments
prefill_roster_column_from_external_fill.rar
(25.32 KiB) Downloaded 177 times
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Prefill roster columns from external files

Post by Gregory Martin »

First, you need to attach the external dictionary to your application: File -> Add Files, select code.dcf. When you run your program, you will associate CODE_DICT with external.csdb.

Then you can loop over all cases where the province matches:
PROC APP_DICT.PROVINCE

    numeric numSchools;
   
    forcase CODE_DICT where CODE_DICT.PROVINCE = APP_DICT.PROVINCE do
        inc
(numSchools);
        APP_DICT.SCHOOL_CODE(numSchools) = CODE_DICT.SCHOOL_CODE;
        APP_DICT.SCHOOL_NAME(numSchools) = CODE_DICT.SCHOOL_NAME;
    endfor;
Note that the item names are prefixed with the dictionary name. This is because you use the same item name in both APP_DICT and CODE_DICT. Working with CSPro logic will be much easier if you use unique names. I often prefix things in a lookup file with LF_.

The above code doesn't properly account for modifying the province. For example, if you enter 1 and then change it to 2, you will still have some schools from province 1 in the table because there are fewer schools in province 2 than 1. If you wanted to allow changes, you could then clear them like this:
    // clear any schools from other provinces that were previously filled in
   
do numeric ctr = numSchools + 1 while ctr <= maxocc(APP_REC)
        APP_DICT.SCHOOL_CODE(ctr) = notappl;
        APP_DICT.SCHOOL_NAME(ctr) = "";
        NUMBER_OF_STUDENTS(ctr) = notappl;
    enddo;
blumski
Posts: 37
Joined: May 7th, 2018, 7:02 am

Re: Prefill roster columns from external files

Post by blumski »

Thank you very much Gregory 🙏
Post Reply