Dear all
I need a logic to automatically insert commas after every number
eg. If there are more than one person for a condition, put commas to separate person numbers. i.e. 1, 3, 6.
but i also want to restrict to only insert numbers and commas on string
thanks
Commas to separate numbers
-
- Posts: 1796
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Commas to separate numbers
I'm not sure exactly what you are trying to do, but this code would create a list of row numbers of all men in the household:
string maleRowNumbers;
do numeric rowNum = 1 while rowNum <= count(SEX)
if SEX(rowNum) = 1 then // add the row number
if length(maleRowNumbers) > 0 then
maleRowNumbers = maleRowNumbers + ", ";
endif;
maleRowNumbers = maleRowNumbers + maketext("%d",rowNum);
endif;
enddo;
Perhaps you can adopt that for your purposes.do numeric rowNum = 1 while rowNum <= count(SEX)
if SEX(rowNum) = 1 then // add the row number
if length(maleRowNumbers) > 0 then
maleRowNumbers = maleRowNumbers + ", ";
endif;
maleRowNumbers = maleRowNumbers + maketext("%d",rowNum);
endif;
enddo;
Re: Commas to separate numbers
it will be Question a Person health condition eg. person 1 and person 2 has TB I should be able to separate 1,3 when i enter
meaning person 1(1) then person 2 (3) but it's all in one question but i didn't want to do it as String-
- Posts: 1796
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Commas to separate numbers
The only way you'll be able to collect this is using a string. A numeric field won't allow you to capture multiple sets of information like this.
Re: Commas to separate numbers
then is there a way to restrict it to only allow numbers and commas
-
- Posts: 1796
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Commas to separate numbers
There is no direct way to do this. You could write logic to test this though, something like:
PROC FIELD
do numeric ctr = 1 while ctr <= length(FIELD)
if poschar("0123456789, ",FIELD[ctr:1]) = 0 then
errmsg("You can only enter digits and commas");
reenter;
endif;
enddo;
do numeric ctr = 1 while ctr <= length(FIELD)
if poschar("0123456789, ",FIELD[ctr:1]) = 0 then
errmsg("You can only enter digits and commas");
reenter;
endif;
enddo;