No announcement yet.

Is number

  • Filter
  • Time
  • Show
Clear All
new posts

  • #41
    Yeah, from the looks of things, the OP is going to have to invent a wheel to match the vehicle he's creating.
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.


    • #42
      "o" is only considered "not non-numeric" when it follows "&", then it means the number is octal. If a number is octal, then neither "8" nor "9" are numeric; they are errors if present in an octal number. VAL checks that.

      "A" to "F" are only numeric if the "number" is HEX, (starts with "&H"). VAL checks that.

      9D9 is format for literal floating point. The "D" stands for "* 10^". For "9D" VAL returns 9; So is the string passed to VAL a number or not? VAL has a problem here being used for IS_NUMERIC.

      "Z" passed to VAL returns 0. But a legit 0 (or 0.0 or &H0000) also returns 0. How to tell a non-numeric 0 return from a numeric 0 return? Second problem for VAL as a IS_NUMERIC detector.

      Throw in the "is decimal point comma or period" from earlier, and I'd say a generic all possibilities IS_NUMERIC function is impossible! You have to code to the set of rules needed in a particular application.



      • #43
        Change the "impossible" in my previous post to "virtually impossible". If the code is long enough, and input parameters are added to select options, then a generic IS_NUMERIC is possible. How long are you willing to wait for answer?


        • #44
          No one thought of REGEXPR?
          Something like:

          #COMPILE EXE
          #DIM ALL
              DIM strInput AS STRING
              strInput = "+.123"
              IF IsNumber(strInput) THEN
                  MSGBOX "True"
                  MSGBOX "False
              END IF
          END FUNCTION
          FUNCTION IsNumber(strINput AS STRING) AS LONG
          LOCAL LngResult AS LONG
          REGEXPR "^[-+]?[0-9]*\.?[0-9]+$" IN strInput TO lngResult
          FUNCTION = (LngResult = 1)
          END FUNCTION


          • #45
            > No one thought of REGEXPR?

            I did, some time ago, but I'm using VBScript regular expressions instead of the built in PB ones.

            I'm using this pattern:

            Pattern: "^[\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?$"

            The initial "^" and the final "$" match the start and the end of the string, to ensure the check spans the whole string.
            The "[\+\-]?" part is the initial plus or minus sign with the "?" multiplier that allows zero or one instance of it.
            The "\d*" is a digit, zero or more times.
            "\.?" is the decimal point, zero or one time.
            The "\d+" part matches a digit one or more times.
            The "(?:[Ee][\+\-]?\d+)?" matches "e+", "e-", "E+" or "E-" followed by one or more digits, with the "?" multiplier that allows zero or one instance of it. (Used to parse numbers like "1.2345678901234567e+029".)

            If somebody wants to translate it to the PB syntax (don't know if it requires changes or not), above you have the explanation of what it does.
            Last edited by José Roca; 16 Oct 2017, 07:21 AM.