Is there a quick and easy way to check a variable to be A-Z? I figure I have to do it character by character but past that I am unsure as character data types allow more then just A-Z.
Is this testing or controlling input? Is it fixed length with no blanks allowed. If so, you should look at a format using A or ! depending on whether you want it upper case, but note that !!!!!! *must* get 6 characters.
How long are the strings? If they are long, then you might experiment with using a bunch of REPLACE statements to convert each letter to "" and then see if you have anything left at the end.
Did you try your idea of checking that each character is between "a" and "z" ? I seems to be correct, but it may not be the most efficient in response time...
Code:
FUNCTION is_A_Z RETURNS LOGICAL (INPUT VarCh AS CHAR) :
DEF VAR tmp AS CHAR NO-UNDO.
DEF VAR cpt AS INTEGER NO-UNDO.
DO cpt = 1 TO LENGTH(VarCh) :
tmp = SUBSTRING(VarCh , cpt, 1).
IF tmp < "a" OR tmp > "z"
THEN RETURN NO.
END.
RETURN YES.
END FUNCTION.
Tamhas, this is for controlling input, and it is only a 2 character field. DevTeam, that method may work, I'll do some testing with it and see how long it takes to check, since it's only a 2 character field the response time shouldn't be to bad.
define variable c as character no-undo format "x(2)".
form c with frame a.
on "any-printable" anywhere do:
if ( lastkey >= asc( "a" ) and lastkey <= asc( "z" ) ) or
( lastkey >= asc( "A" ) and lastkey <= asc( "Z" ) ) then
return.
else
return no-apply.
end.
enable c with frame a.
wait-for "go" of frame a.
If it is always two characters, i.e., one character or blank are not allowable, then the format characters will be the simplest solution. Otherwise, go with something like Tom's.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.