Page 1 of 1
Commas to separate numbers
Posted: March 26th, 2017, 2:16 pm
by MrTaco
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
Re: Commas to separate numbers
Posted: March 27th, 2017, 8:53 am
by Gregory Martin
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.
Re: Commas to separate numbers
Posted: March 27th, 2017, 9:09 am
by MrTaco
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
- eesss.png (2.13 KiB) Viewed 6609 times
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
Re: Commas to separate numbers
Posted: March 27th, 2017, 10:46 am
by Gregory Martin
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
Posted: March 27th, 2017, 2:03 pm
by MrTaco
then is there a way to restrict it to only allow numbers and commas
Re: Commas to separate numbers
Posted: March 27th, 2017, 6:24 pm
by Gregory Martin
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;