Announcement

Collapse
No announcement yet.

Is number

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

  • #21
    Here is a solution.
    If a tests fails, add an OR statement and please let us know. No scientific notation.
    Code:
    FUNCTION isNumeric(Answer AS STRING) AS LONG
      Answer = TRIM$(Answer) 'may be required if right-justified text
      IF (LEN(Answer) = 0)                  OR _
         (VERIFY (Answer , ".-0123456789")) 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 'numeric
    END FUNCTION

    Comment


    • #22
      If right-justified text is accepted,
      then because it is often shown with the minus sign at the beginning, like this:
      Code:
      - 123
      -  12
      -   1
      I would add
      Code:
      Answer = LEFT$(Answer, INSTR(Answer, "-")) & _
      LTRIM$(MID$(Answer, INSTR(Answer, "-") + 1))
      before the IF line.

      Pierre

      Comment


      • #23
        The TRIM$ isn't enough?
        I see, allow spaces after minus sign.
        Might add BYVAL Answer AS STRING since input string is being modified.
        Thank you, will incorporate.


        Good improvements by Pierre, below in post # 24.
        Last edited by Mike Doty; 6 Nov 2015, 10:53 PM.

        Comment


        • #24
          Hey Mike,
          Once started, we could also accept a plus sign prefix...
          Code:
           
          FUNCTION isNumeric2(BYVAL Answer AS STRING) AS LONG
            Answer = TRIM$(Answer) 'Trim spaces, may be required in right-justified text for example
            Answer = LEFT$(Answer, INSTR(Answer, ANY "+-")) & _        'In case of space after the sign,
                     LTRIM$(MID$(Answer, INSTR(Answer, ANY "+-") + 1)) ' "- 123" for example
            'PRINT Answer & "<"
            IF (LEN(Answer) = 0)                   OR _  'Exclude null string
               (VERIFY (Answer , ".-+0123456789")) OR _  'Accept only valid characters
               (INSTR(-1, Answer, "+") > 1)        OR _  'Plus must be on digit's left
               (INSTR(-1, Answer, "-") > 1)        OR _  'Minus must be on digit's left
               (RIGHT$(Answer, 1) = ".")           OR _  'Must not end with a dot
               (TALLY(Answer, ".") > 1)            THEN  'No more than one dot
               EXIT FUNCTION  'Return zero, not a number
            END IF
            FUNCTION = -1 'Its a number
          END FUNCTION
          Last edited by Pierre Bellisle; 6 Nov 2015, 07:33 PM.

          Comment


          • #25
            >...improvements by Pierre...

            'twas easy, I only added a little block on a well made foundation. :-)

            Pierre

            Comment


            • #26
              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, 11:10 AM.

              Comment


              • #27
                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, 11:38 AM.
                <b>George W. Bleck</b>
                <img src='http://www.blecktech.com/myemail.gif'>

                Comment


                • #28
                  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, 11:47 AM.

                  Comment


                  • #29
                    Hello Mike
                    Pretty good but it cannot handle comma

                    Comment


                    • #30
                      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

                      Comment


                      • #31
                        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

                        Comment


                        • #32
                          regarding commas/decimals make sure you read my post #27 as it is already being lost in the static.
                          <b>George W. Bleck</b>
                          <img src='http://www.blecktech.com/myemail.gif'>

                          Comment


                          • #33
                            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

                            Comment


                            • #34
                              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, 05:22 PM. Reason: Correct quote tags amd Mike D's given name
                              Michael Mattias
                              Tal Systems Inc.
                              Racine WI USA
                              mmattias@talsystems.com
                              http://www.talsystems.com

                              Comment


                              • #35
                                > Comma is not numeric.

                                https://en.wikipedia.org/wiki/Decima..._decimal_comma
                                "Not my circus, not my monkeys."

                                Comment


                                • #36
                                  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..?)

                                  Comment


                                  • #37
                                    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.
                                    Michael Mattias
                                    Tal Systems Inc.
                                    Racine WI USA
                                    mmattias@talsystems.com
                                    http://www.talsystems.com

                                    Comment


                                    • #38
                                      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
                                      
                                      '--------------------------------------------------------------------------------
                                      
                                      ... .... . ... . . ... ... .... . .. ... .... .. ... .... .. .... ..

                                      n6jah @ yahoo.com

                                      Comment


                                      • #39
                                        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.
                                        Rod
                                        "To every unsung hero in the universe
                                        To those who roam the skies and those who roam the earth
                                        To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                                        Comment


                                        • #40
                                          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.

                                          "Not my circus, not my monkeys."

                                          Comment

                                          Working...
                                          X