Announcement

Collapse
No announcement yet.

Is number

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

  • Mark Hunter
    replied
    Code:
    Function NonNegativeWholeNumber(ByVal a As String) As Long      ' Boolean
     Local i As Long
    
     'exclude strings such as 0000004
     Local b As String                   '
     b = LTrim$(a,"0")                   '
     If a <> "0" And a <> b Then         '
      Function = 0                       '
      Exit Function                      '
     End If                              '
     
     For i = 1 To Len(a)
      If Asc(a, i) < 48 Or Asc(a, i) > 57 Then Exit For
     Next
     Function = (i > Len(a))
    End Function

    Leave a comment:


  • Mel Bishop
    replied
    RETAIN$ would be a lot simpler and shorter. Just RETAIN$ what you want then check the length of the original string vs. processed string. If they are the same, then it's a number. If not....

    Leave a comment:


  • Mike Doty
    replied
    I should have kept the author's name.
    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

    Leave a comment:


  • Mel Bishop
    replied
    Take a look at RETAIN$.

    Leave a comment:


  • David Clarke
    started a topic Is number

    Is number

    Many years ago there was a function in the language I was using that would return true or false if the string was a number:

    Code:
    MY_STRING = "1234567"
    IF MY_STRING IS NBR THEN PRINT "ITS A NUMBER!"
    Aside from rolling my own is there a way to do this now in PB / WIN?
Working...
X