如何使用Progress 4GL测试字符串是否为数字

Don*_*nna 4 progress-4gl isnumeric

Progress 4GL 是否有测试字符串是否为数字的函数,如 PHP 的 is_numeric($foo) 函数?

我在http://knowledgebase.progress.com/articles/Article/P148549看到了函数示例来测试字符串中的字符是否为数字。看起来它有一个错字,顺便说一句。

但我认为该语言将是一个内置函数。

Aqu*_*lex 5

不需要函数就可以直接进行转换。

ASSIGN dNumber = DECIMAL(cNumber) NO-ERROR. 
IF ERROR-STATUS:ERROR THEN
DO:
    {Handle issues}        
END.
Run Code Online (Sandbox Code Playgroud)

或者如果始终是整数,可以使用 INTEGER 而不是 DECIMAL。


小智 5

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("-").
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)