Consultor Eletrônico



Kbase 18400: 4GL. How To Be Sure Only Numbers Are Entered In Character Field
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   12/07/2005
Status: Unverified

GOAL:

How To Be Sure Only Numbers Are Entered In Character Field

CAUSE:

If you wish to programmatically assure that only numbers are entered into a character field and no alphabetical letters, use the INTEGER function with the NO-ERROR option, then check ERROR-STATUS:ERROR.

This solution will allow decimal values to pass the test.

FIX:

If you wish to programmatically assure that only numbers are entered into a character field and no alphabetical letters, use the INTEGER function with the NO-ERROR option, then check ERROR-STATUS:ERROR.
This solution will allow decimal values to pass the test.

Example code:

DEFINE VARIABLE x AS CHARACTER NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.

UPDATE x.

ASSIGN i = INTEGER(x) NO-ERROR.

IF ERROR-STATUS:GET-MESSAGE(1) "" THEN
MESSAGE "Invalid numeric entered" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "Valid numeric entered" VIEW-AS ALERT-BOX.