multpos

Discussions about CSEntry
Post Reply
lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

multpos

Post 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;
lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

Re: multpos

Post by lls »

Here is the file attached.
How can I make it work with "Check box"?

Thank you
Attachments
multpos.zip
(4.34 KiB) Downloaded 626 times
Gregory Martin
Posts: 1845
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: multpos

Post 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.
Attachments
multpos.zip
(2.76 KiB) Downloaded 560 times
lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

Re: multpos

Post by lls »

Many thanks!
lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

Re: multpos

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

Re: multpos

Post 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.
Attachments
multpos.zip
(2.89 KiB) Downloaded 608 times
Post Reply