I have three questions in roster of listing application.
Q1. Is there any female age 15-49 in household?
Q2. If yes how many?
Q3. Serial number for household.
I want to generate auto serial number in third question fro those households who have female aged 15-49.
Auto serial number generation
-
- Posts: 2
- Joined: February 21st, 2018, 11:35 am
Re: Auto serial number generation
@muhaliraza if your serial number field is an id-variable then you can check the "auto-increment" box in the field properties for your field (right click on the field and choose "field properties"). If the field is auto-increment it will automatically be assigned a sequential value by CSPro.
If your serial number variable is not an id-variable then you will need to implement the auto serial number generation yourself in CSPro logic. The simplest way to do this is to save the last serial number using savesetting() and then retrieve it using loadsetting(). Settings saved using loadsetting()/savesetting() persist between different runs of the application. The logic might look something like this:
If your serial number variable is not an id-variable then you will need to implement the auto serial number generation yourself in CSPro logic. The simplest way to do this is to save the last serial number using savesetting() and then retrieve it using loadsetting(). Settings saved using loadsetting()/savesetting() persist between different runs of the application. The logic might look something like this:
PROC SERIAL
preproc
// Skip if no household members 15-49
ask if NUM_MEMBERS_15_TO_49 > 0;
// Don't change value if it was already entered - don't want to increment
// if we pass back through the field. Have to use visualvalue since in preproc
if visualvalue(SERIAL) = notappl then
// Try to load last saved serial number from settings
//savesetting("LAST_SERIAL", "");
if loadsetting("LAST_SERIAL") = "" then
// Not found - must be first time
SERIAL = 1;
else
// Use last serial number plus 1
SERIAL = tonumber(loadsetting("LAST_SERIAL")) + 1;
endif;
// Save serial for next time
savesetting("LAST_SERIAL", maketext("%d", visualvalue(SERIAL)));
endif;
You would probably also want to make the field protected using the field properties.preproc
// Skip if no household members 15-49
ask if NUM_MEMBERS_15_TO_49 > 0;
// Don't change value if it was already entered - don't want to increment
// if we pass back through the field. Have to use visualvalue since in preproc
if visualvalue(SERIAL) = notappl then
// Try to load last saved serial number from settings
//savesetting("LAST_SERIAL", "");
if loadsetting("LAST_SERIAL") = "" then
// Not found - must be first time
SERIAL = 1;
else
// Use last serial number plus 1
SERIAL = tonumber(loadsetting("LAST_SERIAL")) + 1;
endif;
// Save serial for next time
savesetting("LAST_SERIAL", maketext("%d", visualvalue(SERIAL)));
endif;
Re: Auto serial number generation
@ismaila025 next time please post to a new topic rather than adding your question to a completely unrelated topic like this.
It looks like your server is on a local network (LAN) based on the IP address. Make sure the device you are using is connected to the same LAN. If you are using a tablet or phone that has is a using a cellular connection then it will not be.
It looks like your server is on a local network (LAN) based on the IP address. Make sure the device you are using is connected to the same LAN. If you are using a tablet or phone that has is a using a cellular connection then it will not be.
-
- Posts: 44
- Joined: February 1st, 2018, 9:00 am
Re: Auto serial number generation
@josh Thanks. Actually I want to generate a serial number where there is a women aged 15 to 49, and for those household where there is no women in this age the serial will be blank, and I also want that if the data entry operator will change the field the serial will adjust accordingly.
Forexample
women_15_49 NUM_MEMBERS_15_TO_49 serial
Yes 2 1
No
Yes 1 2
Yes 5 3
No
Yes 3 4
Forexample
women_15_49 NUM_MEMBERS_15_TO_49 serial
Yes 2 1
No
Yes 1 2
Yes 5 3
No
Yes 3 4
Last edited by muhaliraza on February 24th, 2018, 9:50 am, edited 1 time in total.
-
- Posts: 2
- Joined: February 21st, 2018, 11:35 am
Re: Auto serial number generation
well thank you and we solve the problem by change the language
Re: Auto serial number generation
In your example is each line a separate case or is this all within the same case (e.g. roster or repeating form)?
-
- Posts: 44
- Joined: February 1st, 2018, 9:00 am
Re: Auto serial number generation
@josh Its a roster and each row represent a separate household
Re: Auto serial number generation
In that case you don't need to worry about loadsetting/savesetting. That is only needed when you need to seralize across different cases. In a roster you can just use the max function to get the current largest value and add one to that. Something like this:
PROC PER_SERIAL
preproc
// Skip if no women 15 to 49
ask if WOMEN_15_49 = 1;
if max(SERIAL) = default then
// when max returns default there are no previous values in roster so this must be first
SERIAL = 1;
else
// add one to largest value so far
SERIAL = max(SERIAL) + 1;
endif;
preproc
// Skip if no women 15 to 49
ask if WOMEN_15_49 = 1;
if max(SERIAL) = default then
// when max returns default there are no previous values in roster so this must be first
SERIAL = 1;
else
// add one to largest value so far
SERIAL = max(SERIAL) + 1;
endif;
-
- Posts: 44
- Joined: February 1st, 2018, 9:00 am
Re: Auto serial number generation
@josh thanks its working. But there is still an issue. If we go back to the field and change the entry the serial will not change accordingly.