Announcement

Collapse
No announcement yet.

Is number

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • José Roca
    replied
    > 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, 08:21 AM.

    Leave a comment:


  • Stuart McLachlan
    replied
    No one thought of REGEXPR?
    Something like:

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        DIM strInput AS STRING
    
        strInput = "+.123"
    
        IF IsNumber(strInput) THEN
            MSGBOX "True"
        ELSE
            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

    Leave a comment:


  • Dale Yarker
    replied
    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?

    Leave a comment:


  • Dale Yarker
    replied
    "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.


    Leave a comment:


  • Rodney Hicks
    replied
    Yeah, from the looks of things, the OP is going to have to invent a wheel to match the vehicle he's creating.

    Leave a comment:


  • Eric Pearson
    replied
    Clever idea, using the UnusedVar& value, but...

    I'm usually not a fan of VAL because it interprets a ton of non-numeric characters as numeric. For example VAL("9D9") produces "9000000000". These characters...

    01234567890.-+&AaBbCcDdEeFfHhOoQq + CHR$(9,32)

    ...can all be interpreted as "not non-numeric" by VAL. Also, VAL says "9" is not a numeric character if the string starts with &o... lots and lots of pitfalls.

    Leave a comment:


  • Rodney Hicks
    replied
    It seems to me that VAL solves this problem:
    Syntax:
    VAL StrgExpr [, offset] TO ValueVar [, DigitsVar&, UnusedVar&]
    If the Unusedvar$ has content, then StrExpr is not a number even if it has content that have a numeric flavor. The OP wanted to know if it was a number.

    Leave a comment:


  • Jim Robinson
    replied
    I found the IsNumeric routine here some years ago. I'm pretty sure it was something Hutch shared, but it could be someone else... so many contributors here.

    I modified the basic routine to fit some particular needs.
    Code:
    '--------------------------------------------------------------------------------
    '- String Validataion routines:
    '-  IsAlpha     - returns true if all letters                (A-Z,a-z)
    '-  IsAlphaEX   - returns true if all letters and/or blanks  (A-Z,a-z," ")
    '-  IsCapAlpha  - returns true if all capital letters        (A-Z)
    '-  IsNumeric   - returns true if all numbers                (0-9)
    '-  IsNumericEX - returns true if all numbers, commas, decimal points, plus, minus eg: -1,234.56 = True
    '-  IsZIP       - returns true if all numbers and/or dash    (0-9, "-")
    '-  IsDollars   - returns true is all numbers, commas, decimal points, dollar signs (0-9,",",".","$")
    '-  IsAlphaNumeric - returns true if all numbers and/or letters (A-Z,a-z,0-9)
    
    '--------------------------------------------------------------------------------
    '===============================================================================================
    '// Returns 1 if a string is an alpha char (A-Z,a-z)
    FUNCTION IsCapAlpha(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s)
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop529:
       ! mov bl, [eax]
       ! cmp bl, 65
       ! jl  NotAlpha529  ; < 65? Not alpha
       ! cmp bl, 90
       ! jg  NotAlpha529  ; > 90? Not alpha
    Alpha529:
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop529
       ! jmp StartLoop529
    NotAlpha529:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop529:
       FUNCTION = True
    END FUNCTION
    
    FUNCTION IsAlpha(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s)
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop530:
       ! mov bl, [eax]
       ! cmp bl, 65
       ! jl  NotAlpha530  ; < 65? Not alpha
       ! cmp bl, 122
       ! jg  NotAlpha530  ; > 122? Not alpha
       ! cmp bl, 91
       ! jl  Alpha530     ; < 91? Alpha
       ! cmp bl, 97
       ! jl NotAlpha530   ; < 97? Not alpha
    Alpha530:
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop530
       ! jmp StartLoop530
    NotAlpha530:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop530:
       FUNCTION = True
    END FUNCTION
    
    FUNCTION IsAlphaEX(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s)
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop530x:
       ! mov bl, [eax]
       ! cmp bl, 32       ; a blank is ok too
       ! je  Alpha530x
       ! cmp bl, 65
       ! jl  NotAlpha530x  ; < 65? Not alpha
       ! cmp bl, 122
       ! jg  NotAlpha530x  ; > 122? Not alpha
       ! cmp bl, 91
       ! jl  Alpha530x     ; < 91? Alpha
       ! cmp bl, 97
       ! jl NotAlpha530x   ; < 97? Not alpha
    Alpha530x:
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop530x
       ! jmp StartLoop530x
    NotAlpha530x:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop530x:
       FUNCTION = True
    END FUNCTION
    
    '===============================================================================================
    '// Returns 1 if a string is numeric (0-9)
    FUNCTION IsNumeric(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
    
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s)
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop531:
       ! mov bl, [eax]
       ! cmp bl, 48
       ! jl  NotNumeric531  ; < 48? Not numeric
       ! cmp bl, 57
       ! jg  NotNumeric531  ; > 57? Not numeric
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop531
       ! jmp StartLoop531
    NotNumeric531:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop531:
       FUNCTION = True
    END FUNCTION
    
    '// Returns 1 if a string is numeric (0 through 9, and the Plus (+), Minus(-), and  Decimal (.)
    FUNCTION IsNumericEX(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s)
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop533:
       ! mov bl, [eax]
       ! cmp bl, 43
       ! jl  NotNumeric533   ; lower than minus
       ! cmp bl, 46
       ! jle OKgoon533   ;  is decimal, or comma, or plus, or minus
       ! cmp bl, 48
       ! jl  NotNumeric533  ; < 48? Not numeric
       ! cmp bl, 57
       ! jg  NotNumeric533  ; > 57? Not numeric
    OKgoon533:
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop533
       ! jmp StartLoop533
    NotNumeric533:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop533:
       FUNCTION = True
    END FUNCTION
    
    ' like IsNumeric, except allows a DASH
    FUNCTION IsZIP(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s)
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop534:
       ! mov bl, [eax]
       ! cmp bl, 45
       ! je  OKgoon534      ;  is a dash
       ! cmp bl, 48
       ! jl  NotNumeric534  ; < 48? Not numeric
       ! cmp bl, 57
       ! jg  NotNumeric534  ; > 57? Not numeric
    OKgoon534:
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop534
       ! jmp StartLoop534
    NotNumeric534:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop534:
       FUNCTION = True
    END FUNCTION
    
    ' like IsNumeric, except allows a commas, decimals, dollar signs
    FUNCTION IsDollars(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s)
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop535:
       ! mov bl, [eax]
       ! cmp bl, 36
       ! je  OKgoon535      ;  is a $
       ! cmp bl, 44
       ! je  OKgoon535      ;  is a ,
       ! cmp bl, 46
       ! je  OKgoon535      ;  is a .
       ! cmp bl, 48
       ! jl  NotNumeric535  ; < 48? Not numeric
       ! cmp bl, 57
       ! jg  NotNumeric535  ; > 57? Not numeric
    OKgoon535:
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop535
       ! jmp StartLoop535
    NotNumeric535:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop535:
       FUNCTION = True
    END FUNCTION
    
    
    '===============================================================================================
    '// Returns 1 if a string is alphanumeric (A-Z,a-z,0-9)
    FUNCTION IsAlphanumeric(s AS STRING) AS LONG
    #REGISTER NONE
    LOCAL sPtr&, sLen&
       ON ERROR RESUME NEXT
       sPtr = STRPTR(s) - 1
       sLen& = STRPTR(s) + LEN(s)
       ! mov eax, sPtr ;ptr to string
       ! mov ecx, sLen ;addr: end of string
    StartLoop532:
       ! inc eax
       ! cmp eax, ecx
       ! je  EndLoop532
       ! mov bl, [eax]
       ! cmp bl, 65
       ! jl  NotAlpha532   ; < 65? Not alpha
       ! cmp bl, 122
       ! jg  NotNumeric532 ; > 122? Not NotNumeric
       ! cmp bl, 91
       ! jl  Alpha532      ; < 91? Alpha
       ! cmp bl, 97
       ! jl NotAlpha532    ; < 97? Not alpha
    Alpha532:
       ! jmp StartLoop532
    NotAlpha532:
       ! cmp bl, 48
       ! jl NotNumeric532  ; < 48? Not numeric
       ! cmp bl, 57
       ! jg NotNumeric532  ; > 57? Not numeric
       ! jmp StartLoop532
    NotNumeric532:
       FUNCTION = False
       EXIT FUNCTION
    EndLoop532:
       FUNCTION = True
    END FUNCTION
    
    '--------------------------------------------------------------------------------
    

    Leave a comment:


  • Michael Mattias
    replied
    Since value isn't really important, Remove$ can be used to remove spaces, commas and dots, etc before numeric test.
    There's really no difference I can see between
    Code:
        ToTest$ =  REMOVE$(RawString$, some_set_characters_defined_non_numeric)
         CALL testochoice (ToTest$) TO iResult
    AND
    Code:
        ToTest$ =  RETAIN$(RawString$, some_set_characters_defined_are_numeric)
         CALL testochoice (ToTest$) TO iResult
    It's not really in the test, it's in the defining of the allowed characters, their frequency/permitted occurrences, their positions within 'RawString$' and any required or prohibited relationships between and/or among characters.

    The question "Does this string represent a number?" is simply too Insufficient and too incomplete to expect THE ONE TRUE ANSWER.

    Leave a comment:


  • Borje Hagsten
    replied
    Since value isn't really important, Remove$ can be used to remove spaces, commas and dots, etc before numeric test.
    Combination IsCharAlphaNumeric <> 0 and IsCharAlpha = 0 returns following as numeric: 0123456789²³¹
    Try testing 2² (^ should also be sort of numeric, or..?)

    Leave a comment:


  • Eric Pearson
    replied
    > Comma is not numeric.

    https://en.wikipedia.org/wiki/Decima..._decimal_comma

    Leave a comment:


  • Michael Mattias
    replied
    Pretty good but it cannot handle comma
    Comma is not numeric. As Mike Doty says ".. way of looking at comma is that it is not a valid digit, but only for formatting."

    But now (not that it's a 'first' here) a question other than that which was asked is being addressed: it's no longer " does string 'x' represent a number?" but rather it becomes " does string 'x' represent a number or a formatted number?"

    And let me screw up this comma thing (and decimal point thing) forever: in Europe the usage of the comma and the decimal point is reversed from the usage here in the States for formatting numbers.

    Comma usage can be important! Like I saw on a t-shirt worn by one of my classmates at my Silver Sneakers(r) fitness classes:

    {picture of a nice meal}

    Let's eat Grandma.
    Let's eat, Grandma.
    Commas Save Lives!


    MCM
    Last edited by Michael Mattias; 12 Oct 2017, 06:22 PM. Reason: Correct quote tags amd Mike D's given name

    Leave a comment:


  • Chris Chancellor
    replied
    maybe like this ?

    Code:
    #COMPILE EXE
    #DIM ALL
    
    ' Check Numeric.bas
    ' https://forum.powerbasic.com/forum/user-to-user-discussions/programming/61574-is-number/page2
    
    
    FUNCTION PBMAIN () AS LONG
      LOCAL sTitle,MY_STRING, RtString AS STRING
      MY_STRING = "1234567"
      DO
        MY_STRING = INPUTBOX$("Type anything",sTitle,MY_STRING)
        IF LEN(MY_STRING  ) = 0 THEN EXIT DO
        IF IsNumeric(MY_STRING, RtString) THEN
          ?  "ITS A NUMBER!" + $CRLF + _
           STR$(VAL(RtSTRING))
        ELSE
            BEEP
          ? "NOT A NUMBER"
    
        END IF
      LOOP
    
    END FUNCTION
    
     FUNCTION oldisNumeric(Answer AS STRING) AS LONG
      Answer = TRIM$(Answer)
      IF (LEN(Answer) = 0)                OR _
       (VERIFY (Answer , ".-+0123456789"))OR _
       (RIGHT$(Answer,1) = ".")           OR _
       (INSTR(-1,Answer,"-") > 1)         OR _
       (ASC(Answer)=45 AND LEN(Answer)=1) OR _
       (TALLY(Answer,".") > 1) THEN
       EXIT FUNCTION  'exit, return 0 not-numeric
      END IF
      FUNCTION = 1
    END FUNCTION
    
    
    
      FUNCTION isNumeric(BYVAL Answer AS STRING, newAnswer AS STRING) AS LONG
    
      Answer = TRIM$(Answer)
      newAnswer = ""
      'remove all commas if any
      REPLACE "," WITH "" IN answer
      REPLACE " " WITH "" IN answer
    
      IF (LEN(Answer) = 0)                OR _
       (VERIFY (Answer , ".-+0123456789"))OR _
       (RIGHT$(Answer,1) = ".")           OR _
       (RIGHT$(Answer,1) = "+")           OR _
       (RIGHT$(Answer,1) = "-")           OR _
       (INSTR(-1,Answer,"-") > 1)         OR _
       (INSTR(-1,Answer,"+") > 1)         OR _
       (TALLY(Answer,".") > 1) THEN
       EXIT FUNCTION  'exit, return 0 not-numeric
      END IF
      newAnswer = Answer
      FUNCTION = 1
    END FUNCTION

    Leave a comment:


  • George Bleck
    replied
    regarding commas/decimals make sure you read my post #27 as it is already being lost in the static.

    Leave a comment:


  • Chris Chancellor
    replied
    Mike, maybe allow commas to be entered first into function isNumeric
    Initially check Answer for commas and then remove them and then check test results for numeric

    Maybe need a 2 stage process inside function isNumeric
    first stage --> remove commas to become Answer
    second stage --> test Answer for numeric

    Leave a comment:


  • Mike Doty
    replied
    I hear ya.
    One way of looking at comma is that it is not a valid digit, but only for formatting.

    Using INSTR instead of TALLY broke routine using 1.1 so Tally is back.

    Code:
    #DIM ALL
    FUNCTION PBMAIN () AS LONG
      LOCAL sTitle,MY_STRING AS STRING
      MY_STRING = "1234567"
      DO
        MY_STRING = INPUTBOX$("Type anything",sTitle,MY_STRING)
        IF LEN(MY_STRING) = 0 THEN EXIT DO
        IF IsNumeric(MY_STRING) THEN
          sTitle = "ITS A NUMBER!"
        ELSE
          sTitle = "NOT A NUMBER"
          BEEP
        END IF
      LOOP
    END FUNCTION
    
    FUNCTION isNumeric(BYVAL Answer AS STRING) AS LONG
      Answer = TRIM$(Answer)
      IF (LEN(Answer) = 0)                OR _
       (VERIFY (Answer , ".-+0123456789"))OR _
       (RIGHT$(Answer,1) = ".")           OR _
       (RIGHT$(Answer,1) = "+")           OR _
       (RIGHT$(Answer,1) = "-")           OR _
       (INSTR(-1,Answer,"-") > 1)         OR _
       (INSTR(-1,Answer,"+") > 1)         OR _
       (TALLY(Answer,".") > 1) THEN
       EXIT FUNCTION  'exit, return 0 not-numeric
      END IF
      FUNCTION = 1
    END FUNCTION

    Leave a comment:


  • Chris Chancellor
    replied
    Hello Mike
    Pretty good but it cannot handle comma

    Leave a comment:


  • Mike Doty
    replied
    Found some more to exclude as valid
    Others suggested BYVAL which was missing
    Scientific notation is not considered
    https://forum.powerbasic.com/forum/u...umeric?t=43051
    Scientific notation is not considered

    1+1 returns valid so needs more work

    Code:
    #DIM ALL
    FUNCTION PBMAIN () AS LONG                   'ISNUMBER.BAS  so can find in the future
      LOCAL sTitle,MY_STRING AS STRING
      MY_STRING = "1234567"
      DO
        MY_STRING = INPUTBOX$("Type anything",sTitle,MY_STRING)
        IF LEN(MY_STRING) = 0 THEN EXIT DO
        IF IsNumeric(MY_STRING) THEN
          sTitle = "ITS A NUMBER!"
        ELSE
          sTitle = "NOT A NUMBER"
          BEEP
        END IF
      LOOP
    END FUNCTION
    
    FUNCTION isNumeric(BYVAL Answer AS STRING) AS LONG
      Answer = TRIM$(Answer)
      IF (LEN(Answer) = 0)                OR _
       (VERIFY (Answer , ".-+0123456789"))OR _
       (RIGHT$(Answer,1) = ".")           OR _
       (RIGHT$(Answer,1) = "+")           OR _
       (RIGHT$(Answer,1) = "-")           OR _
       (INSTR(-1,Answer,"-") > 1)         OR _
       (TALLY(Answer,".") > 1) THEN
       EXIT FUNCTION  'exit, return 0 not-numeric
      END IF
      FUNCTION = 1
    END FUNCTION
    handle 1+1
    Code:
    FUNCTION isNumeric(BYVAL Answer AS STRING) AS LONG
      Answer = TRIM$(Answer)
      IF (LEN(Answer) = 0)                OR _
       (VERIFY (Answer , ".-+0123456789"))OR _
       (RIGHT$(Answer,1) = ".")           OR _
       (RIGHT$(Answer,1) = "+")           OR _
       (RIGHT$(Answer,1) = "-")           OR _
       (INSTR(-1,Answer,"-") > 1)         OR _
       (INSTR(-1,Answer,"+") > 1)         OR _
       (TALLY(Answer,".") > 1) THEN
       EXIT FUNCTION  'exit, return 0 not-numeric
      END IF
      FUNCTION = 1
    END FUNCTION
    Got rid of tally, more consistent, but maybe tally was better

    Code:
    #DIM ALL
    FUNCTION PBMAIN () AS LONG
      LOCAL sTitle,MY_STRING AS STRING
      MY_STRING = "1234567"
      DO
        MY_STRING = INPUTBOX$("Type anything",sTitle,MY_STRING)
        IF LEN(MY_STRING) = 0 THEN EXIT DO
        IF IsNumeric(MY_STRING) THEN
          sTitle = "ITS A NUMBER!"
        ELSE
          sTitle = "NOT A NUMBER"
          BEEP
        END IF
      LOOP
    END FUNCTION
    
    FUNCTION isNumeric(BYVAL Answer AS STRING) AS LONG
      Answer = TRIM$(Answer)
      IF (LEN(Answer) = 0)                OR _
       (VERIFY (Answer , ".-+0123456789"))OR _
       (RIGHT$(Answer,1) = ".")           OR _
       (RIGHT$(Answer,1) = "+")           OR _
       (RIGHT$(Answer,1) = "-")           OR _
       (INSTR(-1,Answer,".") > 1)         OR _
       (INSTR(-1,Answer,"+") > 1)         OR _
       (INSTR(-1,Answer,"-") >1)   THEN
       EXIT FUNCTION  'exit, return 0 not-numeric
      END IF
      FUNCTION = 1
    END FUNCTION

    Last edited by Mike Doty; 11 Oct 2017, 12:47 PM.

    Leave a comment:


  • George Bleck
    replied
    Just to stir the pot a little but also just so it is said... remember that MANY regions use the comma, period, and space differently to represent the radix and thousands separator characters.

    Whatever function you use needs to be regionally specific OR it would require you code some really complex rulesets to allow all.

    These all could be considered valid numbers...
    • 1234.56
    • 1234,56
    • 1,234.56
    • 1.234,56
    • 1 234.56
    • 1 234,56


    Seeing a number like 12,345 could be VERY confusing depending on context.

    Is it 12 thousand, three hundred forty-five?
    or is it 12 and 345 thousandths?


    Last edited by George Bleck; 11 Oct 2017, 12:38 PM.

    Leave a comment:


  • Mike Doty
    replied
    Verify also needed to check for +
    Code:
    #DIM ALL
    FUNCTION PBMAIN () AS LONG
      LOCAL sTitle,MY_STRING AS STRING
      MY_STRING = "1234567"
      DO
        MY_STRING = INPUTBOX$("Type anything",sTitle,MY_STRING)
        IF LEN(MY_STRING) = 0 THEN EXIT DO
        IF IsNumeric(MY_STRING) THEN
          sTitle = "ITS A NUMBER!"
        ELSE
          sTitle = "NOT A NUMBER"
          BEEP
        END IF
      LOOP
    END FUNCTION
    
    FUNCTION isNumeric(Answer AS STRING) AS LONG
      Answer = TRIM$(Answer)
      IF (LEN(Answer) = 0)                OR _
       (VERIFY (Answer , ".-+0123456789"))OR _
       (RIGHT$(Answer,1) = ".")           OR _
       (INSTR(-1,Answer,"-") > 1)         OR _
       (ASC(Answer)=45 AND LEN(Answer)=1) OR _
       (TALLY(Answer,".") > 1) THEN
       EXIT FUNCTION  'exit, return 0 not-numeric
      END IF
      FUNCTION = 1
    END FUNCTION








    Last edited by Mike Doty; 11 Oct 2017, 12:10 PM.

    Leave a comment:

Working...
X