Hii Cspro users,
Is anybody know how to modify auto Increment in Cspro.
In my case I have two IDs village code and HH no. I have applied auto-increment to HH no but when village code changes HH no increase as usual. For example
1st case - Village code =1 and HH no=1
2nd case - Village code =1 and HH no=2 and so on.
but when village code changes to 2 then
11th case - Village code =2 and HH no becomes 11 but i need here again 1.
What is the code for this?
Modify auto Increment
Re: Modify auto Increment
You can use the keylist function to see what the highest HH no is for the village code entered and then use one greater than that.
PROC HOUSEHOLD
preproc
// Get case ids for cases already entered
list string caseIdList;
keylist(AUTOINCRVILLHH_DICT,caseIdList);
// Find largest household number in the list
// in same village as selected in previous question
numeric maxHHNoForVillage = 0;
do numeric i = 1 while i <= length(caseIdList)
string caseId = caseIdList(i);
// Extract village code from case id string
// Positions and length in [] will vary depending on
// dictionary. Change to match your dictionary.
numeric v = tonumber(caseId[1:2]);
// Check if same as selected village
if v = VILLAGE then
// Extract household number from case id string
// Position and length used in [] will vary depending on
// dictionary. Change to match your dictionary.
numeric hh = tonumber(caseId[3:2]);
// Check if household number is bigger than
// what we have found so far.
if hh > maxHHNoForVillage then
maxHHNoForVillage = hh;
endif;
endif;
enddo;
// Set household number to one bigger than
// largest household number already in data file
// for this village.
HOUSEHOLD = maxHHNoForVillage + 1;
preproc
// Get case ids for cases already entered
list string caseIdList;
keylist(AUTOINCRVILLHH_DICT,caseIdList);
// Find largest household number in the list
// in same village as selected in previous question
numeric maxHHNoForVillage = 0;
do numeric i = 1 while i <= length(caseIdList)
string caseId = caseIdList(i);
// Extract village code from case id string
// Positions and length in [] will vary depending on
// dictionary. Change to match your dictionary.
numeric v = tonumber(caseId[1:2]);
// Check if same as selected village
if v = VILLAGE then
// Extract household number from case id string
// Position and length used in [] will vary depending on
// dictionary. Change to match your dictionary.
numeric hh = tonumber(caseId[3:2]);
// Check if household number is bigger than
// what we have found so far.
if hh > maxHHNoForVillage then
maxHHNoForVillage = hh;
endif;
endif;
enddo;
// Set household number to one bigger than
// largest household number already in data file
// for this village.
HOUSEHOLD = maxHHNoForVillage + 1;
-
- Posts: 63
- Joined: May 15th, 2018, 1:18 am
Re: Modify auto Increment
Thanks josh,
It works well.
It works well.