Page 1 of 1

multpos

Posted: December 4th, 2012, 6:58 pm
by lls
The code below was in an example file (multpos) made by Gregory Martin. It convert alpha into numeric.
It seems that it works only if the alpha field is set to "Text" and doesn't if set to "Check box"
I would like to use this with an alpha field set to "Check box" and have ABC...Z converted into numeric 1 to 26. How can I do that?

Thank you

Code: Select all

PROC GLOBAL

alpha (26) alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


PROC MULTPOS_FF

preproc

	set behavior() canenter(notappl) on(noconfirm);


PROC MULTALPH

PROC NUMBERS

preproc

	if curocc() <= length(strip(MULTALPH)) then
		NUMBERS = poschar(MULTALPH[curocc():1],alphabet);

	else
		NUMBERS = notappl;

	endif;

	noinput;

Re: multpos

Posted: December 4th, 2012, 7:03 pm
by lls
Here is the file attached.
How can I make it work with "Check box"?

Thank you

Re: multpos

Posted: December 5th, 2012, 7:55 am
by Gregory Martin
The reason this didn't work was because my example assumed that all values entered into the field would be upper case. The code can be fixed by adding a toupper statement to the logic:
NUMBERS = poschar(toupper(MULTALPH[curocc():1]),alphabet);
See attached.

Re: multpos

Posted: December 5th, 2012, 10:43 am
by lls
Many thanks!

Re: multpos

Posted: December 8th, 2012, 5:52 pm
by lls
Using this method, is it possible to include 88 (other) and 99 (don't know) with some kind of special characters?

ø = 88
? = 99

Re: multpos

Posted: December 10th, 2012, 1:03 pm
by Gregory Martin
You can definitely do this, but not as simply. Like so:
PROC GLOBAL

alpha (26) alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


function characterToNumber(alpha (1) char)

    
numeric response = poschar(toupper(char),alphabet);

    
if not response then // not in A-Z=

        
if char = 'ø' then          response = 88;
        
elseif char = '?' then      response = 99;
        
else                        response = -1; // invalid character
        endif;

    
endif;

    characterToNumber = response;

end;


PROC MULTPOS_FF

preproc

    
set behavior() canenter(notappl) on(noconfirm);


PROC NUMBERS

preproc

    
if curocc() <= length(strip(MULTALPH)) then
        NUMBERS = characterToNumber(MULTALPH[
curocc():1]);

    
else
        NUMBERS =
notappl;

    
endif;
See attached.