Commas to separate numbers

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Commas to separate numbers

Post 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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Commas to separate numbers

Post 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.
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Re: Commas to separate numbers

Post 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
eesss.png (2.13 KiB) Viewed 6373 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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Commas to separate numbers

Post 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.
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Re: Commas to separate numbers

Post by MrTaco »

then is there a way to restrict it to only allow numbers and commas
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Commas to separate numbers

Post 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;
Post Reply