Results 1 to 6 of 6

Thread: yet another isNumeric question

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    2

    Talking yet another isNumeric question

    Apparently letters that can evaluate as numbers pass VB's isNumeric function. Such as "e"

    Are there any other letter-based expressions that pass isNumeric? Is there a function that genuinely checks to make sure the data is composed of digits and digits only? Or does that have to be customized...

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: yet another isNumeric question

    Originally posted by bitsy
    Apparently letters that can evaluate as numbers pass VB's isNumeric function. Such as "e"
    What do you mean?

    This produces "I'm not"

    VB Code:
    1. If IsNumeric("e") Then
    2.     MsgBox "I'm Numeric"
    3. Else
    4.     MsgBox "I'm not"
    5. End If

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    The reason is that numbers can be things like 10E14.

    Numbers can have period, + signs - signs etc.

    Change the contents of the first string in the code sample to match what you think a number must contain
    [code]
    Function IsANumber(str as String) as Boolean
    Dim nums as String
    nums = "1234567890-."
    for x = 1 to len(str)
    If instr(nums,mid(str,x,1)=0 then
    IsANumberr=False
    Exit Function
    End If
    next x
    IsANumber= True
    End Function

  4. #4
    Lively Member
    Join Date
    Jul 2001
    Location
    NY
    Posts
    89
    e is for exponents and d is for decimals. I usually force the the text box only to accept 0-9 and .
    VB Code:
    1. If IsNumeric("6e2") Then
    2.     MsgBox "I'm Numeric"
    3. Else
    4.     MsgBox "I'm not"
    5. End If
    6.  
    7.  
    8. If IsNumeric("6d2") Then
    9.     MsgBox "I'm Numeric"
    10. Else
    11.     MsgBox "I'm not"
    12. End If

    AndyL

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    2
    thanks for the help. The custom function works great.

  6. #6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width