Hi Guys
I need a restrict rule for restricting a province according to district codes
eg. Province = 1 (District code = 101 - 108), so i want to affiliate 101 - 108 to province 1..
and so no capturing will done outside those bracket.
I tried this rule... but it's not working
if PROVINCE = 1 elseif then DISTRICT >= 101 and then DISTRICT <= 108
then skip to SCHOOL_QUESTIONNAIRE_NUMBER;
if PROVINCE = 2 elseif then DISTRICT >= 221 and then DISTRICT <= 228
then skip to SCHOOL_QUESTIONNAIRE_NUMBER;endif
Thabiso
Restrict numbering
Re: Restrict numbering
Try something like the following:
if PROVINCE = 1 then
if not DISTRICT in 101:108 then
errmsg("Invalid district");
reenter;
endif;
elseif PROVINCE = 2 then
if not DISTRICT in 221:228 then
errmsg("Invalid district");
reenter;
endif;
endif;
if not DISTRICT in 101:108 then
errmsg("Invalid district");
reenter;
endif;
elseif PROVINCE = 2 then
if not DISTRICT in 221:228 then
errmsg("Invalid district");
reenter;
endif;
endif;
Re: Restrict numbering
Thanks Josh it worked...
Re: Restrict numbering
i also want to restrict Barcode with Response code
Response code = 1 means there's blood taken and there's blood taken.
Response code = 2 means no blood taken and there's no barcode.
it shouldn't allow 2 if there's barcode on response code..
and it shouldn't allow 1 if there's no barcode on response code..
Response code = 1 means there's blood taken and there's blood taken.
Response code = 2 means no blood taken and there's no barcode.
it shouldn't allow 2 if there's barcode on response code..
and it shouldn't allow 1 if there's no barcode on response code..
Re: Restrict numbering
Hi Josh
I have just realized that "0" doesn't appear when when you write any number that starts with "0"
what can I can do to make sure it appears.
Thanks
Thabiso
I have just realized that "0" doesn't appear when when you write any number that starts with "0"
what can I can do to make sure it appears.
Thanks
Thabiso
Re: Restrict numbering
On Windows if you set zero-fill in the data dictionary to true for a numeric item then leading zeros will appear. On Android the leading zeros will not be displayed when editing the number but the data will be stored with the leading zeros in the data file.
Re: Restrict numbering
Hi Josh
I did set zero fill on my dict but now when i convert it to SPSS it doesn't show the "0"
it only show on the data capturing file
Thanks
Thabiso
I did set zero fill on my dict but now when i convert it to SPSS it doesn't show the "0"
it only show on the data capturing file
Thanks
Thabiso
Re: Restrict numbering
There may be a setting in SPSS. I don't have SPSS so I don't know. Try looking in the SPSS documentation or maybe someone else on the forum who uses SPSS can help.
Re: Restrict numbering
if I use alphanumeric is the a code that I can apply to only accept numeric "0123456789"
Re: Restrict numbering
You could convert the alpha to a number using the tonumber()function and if it is not a number then the result will be the special value "default". Something like:
If you want to be more strict you will need to loop through each digit and make sure it is a number. You can create a function to do this:
Then you can use it like this:
if tonumber(MYALPHA) = default then
errmsg("Enter a valid number");
reenter;
endif;
The limitation here is that if you have something that starts with a number but has non-number characters at the end then it will not give you an error. For example tonumber("Hello1234") will give you default and fail the above test but tonumber("1234Hello") will result in the number 1234 and pass. This will also work with decimal numbers.errmsg("Enter a valid number");
reenter;
endif;
If you want to be more strict you will need to loop through each digit and make sure it is a number. You can create a function to do this:
// Determine if a string is made up of all numeric digits
function isNumeric(string s)
numeric i;
isNumeric = 1; // assume is number
do i = 1 while i <= length(strip(s))
// check if ith is a number between 0 and 9
if pos(s[i:1], "0123456789") = 0 then
// it is not so set return value to false
isNumeric = 0;
break;
endif;
enddo;
end;
function isNumeric(string s)
numeric i;
isNumeric = 1; // assume is number
do i = 1 while i <= length(strip(s))
// check if ith is a number between 0 and 9
if pos(s[i:1], "0123456789") = 0 then
// it is not so set return value to false
isNumeric = 0;
break;
endif;
enddo;
end;
Then you can use it like this:
if not isNumeric(MYALPHA) then
errmsg("Enter a valid number");
reenter;
endif;
errmsg("Enter a valid number");
reenter;
endif;