Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test if string is numeric using Progress 4GL

Does Progress 4GL have a function for testing whether a string is numeric, like PHP's is_numeric($foo) function?

I've seen the function example at http://knowledgebase.progress.com/articles/Article/P148549 to test if a character in a string is numeric. Looks like it has a typo, btw.

But I would think the language would be a built-in function for this.

like image 328
Donna Avatar asked Oct 10 '13 13:10

Donna


1 Answers

I was looking at this myself recently. The approved answer given to this doesn't work in 100% situations.

If the user enters any of the following special string characters: ? * - or + the answer won't work.
A single plus or minus(dash) is converted to 0 which you may not want.
A single question mark character is valid value which progress recognises as unknown value at which again you may not want.
A single or group asterisks on their own also get converted to 0.
If you run the following code you'll see what I mean.

DISP DECIMAL("*")
     DECIMAL("**")
     DECIMAL("?")
     DECIMAL("+")
     DECIMAL("-").

The following additional code maybe useful to get around this

DEFINE VARIABLE iZeroCode    AS INTEGER   NO-UNDO.
DEFINE VARIABLE iNineCode    AS INTEGER   NO-UNDO.
DEFINE VARIABLE chChar       AS CHARACTER NO-UNDO.

ASSIGN iZeroCode = ASC("0")
       iNineCode = ASC("9")
       chChar    = SUBSTRING(cNumber,1,1).                           

IF NOT(ASC(chChar) >= iZeroCode AND ASC(chChar) <= iNineCode)    THEN DO:
    MESSAGE "Invalid Number..." VIEW-AS ALERT-BOX.
END.
like image 145
ns2016 Avatar answered Nov 03 '22 01:11

ns2016