How to get run time errors

how to handle run time errors, and display user defined message

for example i want to validate a date value, i declare it as character and validate.


DEFINE VARIABLE m_date AS CHARACTER INIT '10/r3/00' NO-UNDO.
DISP DATE(m_date).


**invalid date input.(85)

" how to handle these type of errors and to display programmer defined message for example "not a valid date" "
 
how to handle run time errors, and display user defined message

for example i want to validate a date value, i declare it as character and validate.


DEFINE VARIABLE m_date AS CHARACTER INIT '10/r3/00' NO-UNDO.
DISP DATE(m_date).


**invalid date input.(85)

" how to handle these type of errors and to display programmer defined message for example "not a valid date" "

The next sample should work.

Code:
DEFINE VARIABLE cDate       AS CHARACTER    FORMAT "xx-xx-xxxx".
DEFINE VARIABLE dDate       AS DATE         FORMAT "99-99-9999".
DEFINE FRAME DateFrame 
    cDate HELP "Press <F2> TO accept input" WITH SIDE-LABELS.
/* Accept only numbers in input field */
ON 'ANY-PRINTABLE':U OF cDate IN FRAME DateFrame
DO:
    /* Simulate pressing '?' in a datefield */
    IF KEYFUNCTION(LASTKEY) = "?" THEN
        ASSIGN SELF:SCREEN-VALUE = "".
    IF NOT(KEYFUNCTION(LASTKEY) >= "0" AND
           KEYFUNCTION(LASTKEY) <= "9")
        THEN RETURN NO-APPLY.
 
    RETURN.
END.
/* if the enter key is pressed then simulate a go */
ON 'RETURN':U OF cDate IN FRAME DateFrame
DO:
    APPLY "GO" TO SELF.
    RETURN.
END.
 
/* on 'go' check input date. if valid display, if not valid show error */
ON 'GO':U OF FRAME DateFrame 
DO:
    ASSIGN dDate = DATE(cDate:INPUT-VALUE) NO-ERROR.
    IF ERROR-STATUS:ERROR THEN
    DO:
        MESSAGE " USER DEFINED ERROR : DATE NOT correct" 
            VIEW-AS ALERT-BOX.
        ASSIGN cDate:SCREEN-VALUE = "".
    END.
    ELSE
        DISPLAY REPLACE(STRING(dDate,"99-99-9999"),"-","") @ cDate
            WITH FRAME DateFrame.
    RETURN.
END.
/* Open input field to accept data */
ENABLE cDate WITH FRAME DateFrame.
 
WAIT-FOR CLOSE OF THIS-PROCEDURE.
 
Back
Top