OpenEdge Study - QAD

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1173|回复: 2

判断字符串是纯字符,整形,小数或者数值

[复制链接]
  • TA的每日心情
    擦汗
    7 天前
  • 签到天数: 1176 天

    连续签到: 3 天

    [LV.10]以坛为家III

    611

    主题

    1337

    帖子

    2万

    积分

    管理员

    进击的思考者

    Rank: 9Rank: 9Rank: 9

    积分
    29126
    发表于 2015-12-16 22:08:19 | 显示全部楼层 |阅读模式
    可以作为函数库,放在自己的.I文件中,以便使用。


    FUNCTION fn-ISCHAR RETURN LOGICAL (INPUT ip_textin AS CHAR):  /* via Marco Aurelio */
    DEFINE VAR VA-INT AS DECIMAL NO-UNDO.
    ip_textin=trim(ip_textin).
    IF ip_textin ="" OR ip_textin = ? THEN RETURN NO.
    VA-INT = DECIMAL(ip_textin) NO-ERROR.
    RETURN ERROR-STATUS:ERROR.       /* Does not include numbers */
    END FUNCTION.

    FUNCTION fn-ISDECIMAL RETURN LOGICAL (INPUT ip_textin AS CHAR):
    DEFINE VAR va-value AS DECIMAL NO-UNDO.
    ip_textin=trim(ip_textin).
    IF ip_textin ="" OR ip_textin = ? THEN RETURN NO.
    ASSIGN va-value = DECIMAL(ip_textin) no-error.
    RETURN NOT ERROR-STATUS:ERROR.
    END FUNCTION.

    FUNCTION fn-ISINTEGER RETURN LOGICAL (INPUT ip_textin AS CHAR):
    DEFINE VAR va-value AS INTEGER NO-UNDO.
    ip_textin=trim(ip_textin).
    IF ip_textin ="" OR ip_textin = ? THEN RETURN NO.
    ASSIGN va-value = INTEGER(ip_textin) NO-ERROR.
    IF error-status:error THEN RETURN NO.      /* Catch chars */
    IF decimal(ip_textin) - va-value <> 0 THEN return NO. /* Catch decimal - integer. */
    RETURN YES.
    END FUNCTION.

    FUNCTION fn-IsNumber RETURNS LOGICAL      /* From Jeff Pilant */
      (INPUT ip_textin as character) :
      DEFINE VARIABLE VA-SubStr                 AS CHARACTER NO-UNDO.
      DEFINE VARIABLE VA-NumCommas              AS INTEGER   NO-UNDO.
      DEFINE VARIABLE VA-NumPeriods             AS INTEGER   NO-UNDO.
      DEFINE VARIABLE VA-IntegerPart            AS CHARACTER NO-UNDO.
      DEFINE VARIABLE cComma                    AS CHARACTER NO-UNDO INITIAL ",".
      DEFINE VARIABLE cPeriod                   AS CHARACTER NO-UNDO INITIAL ".".
      DEFINE VARIABLE VA-iCount                 AS INTEGER   NO-UNDO.
      DEFINE VARIABLE VA-IntegerDelimiterCount  AS INTEGER   NO-UNDO.

      IF ip_textin = ? THEN RETURN NO.
      IF TRIM(ip_textin, "+-0123456789.,") <> "" THEN RETURN NO.
      VA-SubStr = SUBSTRING(ip_textin, 1, 1).
      IF TRIM(VA-SubStr, "+-") = ""
      THEN ip_textin = SUBSTRING(ip_textin, 2).
      ELSE VA-SubStr = "+".
      IF TRIM(ip_textin, "0123456789.,") <> "" THEN RETURN NO.
      IF SESSION:NUMERIC-FORMAT = "AMERICAN" THEN
      DO:
        VA-NumPeriods = NUM-ENTRIES(ip_textin, cPeriod).
        IF VA-NumPeriods > 2 THEN RETURN NO.
        VA-IntegerPart = ENTRY(1, ip_textin, cPeriod).

        VA-NumCommas = NUM-ENTRIES(VA-IntegerPart, cComma).
        IF VA-NumCommas > 1 then
        DO:
          VA-IntegerDelimiterCount = NUM-ENTRIES(VA-IntegerPart, cComma).
          IF LENGTH(ENTRY(1, VA-IntegerPart, cComma)) > 3 THEN RETURN NO.
          IF VA-IntegerDelimiterCount > 1 THEN
          DO VA-iCount = 2 TO VA-IntegerDelimiterCount:
            IF LENGTH(ENTRY(VA-iCount, VA-IntegerPart, cComma)) <> 3 THEN RETURN NO.
          END.
        END.
        IF VA-NumPeriods > 1 THEN
        IF INDEX(ENTRy(2, ip_textin, cPeriod), cComma) > 0 THEN RETURN NO.
        RETURN YES.
      END.
      IF SESSION:NUMERIC-FORMAT = "EUROPEAN" THEN
      DO:
        VA-NumCommas = NUM-ENTRIES(ip_textin, cComma).
        IF VA-NumCommas > 2 THEN RETURN NO.
        VA-IntegerPart = entry(1, ip_textin, cComma).
        VA-NumPeriods = NUM-ENTRIES(VA-IntegerPart, cPeriod).
        IF VA-NumPeriods > 1 THEN
        DO:
          VA-IntegerDelimiterCount = NUM-ENTRIES(VA-IntegerPart, cPeriod).
          IF LENGTH(ENTRY(1, VA-IntegerPart, cPeriod)) > 3 THEN RETURN NO.
          IF VA-IntegerDelimiterCount > 1 THEN
          DO VA-iCount = 2 TO VA-IntegerDelimiterCount:
            IF LENGTH(ENTRY(VA-iCount, VA-IntegerPart, cPeriod)) <> 3 THEN RETURN NO.
          END.
        END.
        IF VA-NumCommas > 1 THEN
        IF INDEX(ENTRY(2, ip_textin, cComma), cPeriod) > 0 THEN RETURN NO.
        RETURN YES.
      END.
      RETURN NO.
    END FUNCTION.

    FUNCTION fn-ISCHAR-loop RETURN LOGICAL (INPUT ip_textin AS CHARACTER):  /* from Carlos Eduardo P. Carvalho */
    DEFINE VARIABLE va-loop   AS INTEGER NO-UNDO.
    DEFINE VARIABLE va-letter AS CHARACTER FORMAT "X(70)" NO-UNDO.
    ip_textin=trim(ip_textin).
    IF ip_textin ="" OR ip_textin = ? THEN RETURN NO.

    DO va-loop = 0  TO 25:       /* WORKS NO MATTER CODE PAGE */
      va-letter = va-letter +  CHR((ASC("A")) + va-loop).
    END.
      va-letter = va-letter + "0123456789".         /* include numbers */
    DO va-loop = 1 TO LENGTH(ip_textin):
       IF INDEX(va-letter, SUBSTRING(ip_textin,va-loop,1)) = 0 THEN
         RETURN NO.
    END.
    RETURN YES.
    END FUNCTION.

    FUNCTION fn-ISCHAR-trim RETURN LOGICAL (INPUT ip_textin AS CHAR):      /* me */
    IF TRIM(ip_textin) = "" OR ip_textin = ? THEN RETURN NO.
    RETURN TRIM(ip_textin, "ABCEDFGHIJKLMNOPQRSTUVWXYZ") = "". /* could add numbers here if you wanted */
    END FUNCTION.

    FUNCTION fn-ISDECIMAL-loop RETURN LOGICAL (INPUT ip_textin AS CHARACTER):   /* modeled after the fn-ischar-loop */
    DEFINE VARIABLE va-loop AS INTEGER NO-UNDO.
    IF ip_textin ="" OR ip_textin = ? THEN RETURN NO.
    DO va-loop = 1 TO LENGTH(ip_textin):
        IF INDEX("0123456789.,-+":U, SUBSTRING(ip_textin,va-loop,1)) = 0 THEN
           RETURN NO.
    END.
    RETURN YES.
    END FUNCTION.

    FUNCTION fn-ISDECIMAL-trim RETURN LOGICAL (INPUT ip_textin AS CHAR):     /* Idea From Jeff Pilant */
    IF TRIM(ip_textin) = "" OR ip_textin = ? then RETURN NO.
    RETURN TRIM(ip_textin, "0123456789-+.,") = "".  /* includes dash period and comma */
    END FUNCTION.

    FUNCTION fn-ISINTEGER-trim RETURN LOGICAL (INPUT ip_textin AS CHAR):    /* Idea From Jeff Pilant */
    IF TRIM(ip_textin) = "" OR ip_textin = ? THEN RETURN NO.
    RETURN TRIM(ip_textin, "0123456789-+") = "".
    END FUNCTION.




    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    该会员没有填写今日想说内容.
  • TA的每日心情
    奋斗
    2017-11-8 15:28
  • 签到天数: 7 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    0

    主题

    23

    帖子

    86

    积分

    注册会员

    Rank: 2

    积分
    86
    发表于 2015-12-16 22:11:52 | 显示全部楼层
    辛苦了赞
    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    2019-3-28 15:34
  • 签到天数: 9 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    2

    主题

    18

    帖子

    84

    积分

    注册会员

    Rank: 2

    积分
    84
    发表于 2017-5-11 02:38:34 | 显示全部楼层
    学习了,谢谢分享
    该会员没有填写今日想说内容.
    *滑动验证:
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|小黑屋|手机版|OpenEdge Study - QAD ( 沪ICP备15012660号 QAD OpenEdge Study385468063

    GMT+8, 2019-11-21 14:52 , Processed in 0.600108 second(s), 31 queries .

    Powered by Discuz! X3.4 Licensed

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表