用户定义的日期错误

时间:2014-01-23 13:03:25

标签: validation date progress-4gl

如何验证错误日期的错误。 我想在离开触发器本身验证

我使用了以下代码,但没有工作:(

可以帮助一些人。

先谢谢。

此致 拉维。 dtJoin是一个数据库字段。

以下是我试过的代码。

=============================================== =

    DEFINE VARIABLE vDATE   AS DATE        NO-UNDO.
    DEFINE VARIABLE vToday  AS DATE        NO-UNDO.

    DEFINE VARIABLE leap    AS LOGICAL     NO-UNDO.

    ASSIGN
    vToday = DATE(DtJoin:SCREEN-VALUE) NO-ERROR.

    IF ((YEAR(vToday) MODULO 400 = 0)OR(year(vToday) MODULO 4 = 0)AND(year(vToday) MODULO 100 = 0) )
    THEN
        leap = TRUE.
    ELSE
        leap = FALSE.

        MESSAGE MONTH(vToday)
            VIEW-AS ALERT-BOX INFO BUTTONS OK.
        /* IF MONTH(vToday) = 1 /* OR MONTH(vToday) = 3 OR MONTH(vToday) = 5 OR MONTH(vToday) = 7 OR MONTH(vToday) = 8 OR MONTH(vToday) = 10 OR MONTH(vToday) = 12 */ THEN
    IF DATE(vToday) > 31  THEN
       MESSAGE "Invalid Date"
           VIEW-AS ALERT-BOX ERROR BUTTONS OK.
    ELSE
      ASSIGN
      vdate = vToday.
   */
   /*
    ELSE IF MONTH(vToday) = 4 OR MONTH(vToday) = 6 OR MONTH(vToday) = 9 OR MONTH(vToday) = 11 THEN
    IF DATE(vToday) > 30 THEN
       MESSAGE
       VIEW-AS ALERT-BOX ERROR BUTTONS OK.
    ELSE
      ASSIGN
      vdate = vToday.

    ELSE IF MONTH(vToday) = 2 AND leap THEN
        IF DATE(vToday) > 29 THEN
           MESSAGE 
               VIEW-AS ALERT-BOX ERROR BUTTONS OK.
        ELSE
         ASSIGN
             vdate = vToday.
    ELSE 
        IF DATE(vToday) > 28 THEN
            MESSAGE 
                VIEW-AS ALERT-BOX ERROR BUTTONS OK.
        ELSE 
            ASSIGN
                vDate = vToday.
                */
    END.   

1 个答案:

答案 0 :(得分:1)

你让自己变得非常困难!

应该这样做:

ASSIGN
    vToday = DATE(DtJoin:SCREEN-VALUE) NO-ERROR.

IF vToday = ? THEN DO:
    MESSAGE "Enter another date" VIEW-AS ALERT-BOX.
END.

您还可以将输入字段设置为日期类型,这基本上可以自行处理。如果你不想要,你可以在字段的LEAVE触发器中插入这样的东西:

DEFINE VARIABLE vToday AS DATE.

ASSIGN
    vToday = DATE(SELF:SCREEN-VALUE) NO-ERROR.

IF vToday = ? THEN DO:
    MESSAGE "Enter another date" VIEW-AS ALERT-BOX ERROR.
    RETURN NO-APPLY.
END.