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
Prefill roster columns from external files
Prefill roster columns from external files
- Attachments
-
- prefill_roster_column_from_external_fill.rar
- (25.32 KiB) Downloaded 244 times
-
- Posts: 1803
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Prefill roster columns from external files
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:
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:
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_.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;
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;
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;
Re: Prefill roster columns from external files
Thank you very much Gregory