Results 1 to 9 of 9

Thread: If text in textbox is not numeric then..

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    134

    If text in textbox is not numeric then..

    How would I create a command that checks to see the text in a textbox and if its not numeric then to display a message..

    For example..

    Code:
    Private Sub cmdgo_Click()
    If Text1.text = Not Numeric Then
    Msgbox "Not Numeric"
    End If


    Thankyou

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: If text in textbox is not numeric then..

    Code:
    Private Sub cmdgo_Click()
    If IsNumeric(Text1.text) =False Then
    Msgbox "Not Numeric"
    End If

  3. #3
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: If text in textbox is not numeric then..

    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: If text in textbox is not numeric then..

    Code:
    If Not IsNumeric(Text1.Text) Then

  5. #5
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: If text in textbox is not numeric then..

    That's another way to use my code Zach_VB6

  6. #6
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: If text in textbox is not numeric then..


  7. #7
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: If text in textbox is not numeric then..

    Quote Originally Posted by Zach_VB6
    Code:
    If Not IsNumeric(Text1.Text) Then
    Note that if the textbox reads "1/2", IsNumeric will say that it is not numeric because the forward slash is not considered a numeric by IsNumeric. Some might consider this a weakness. Other examples can also be identified, such as the factorial sign !, brackets, and braces. On the other hand, parentheses are considered numeric, so I think there is some judgment calls going on here.

    Just my $0.02.
    Doctor Ed

  8. #8
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: If text in textbox is not numeric then..

    You could
    n Code:
    1. Private Sub cmdgo_Click()
    2. text1.text =  replace (text1.text,"/","")
    3.  
    4. If IsNumeric(Text1.text) =False Then
    5. Msgbox "Not Numeric"
    6. End If
    Quote Originally Posted by Code Doc
    Note that if the textbox reads "1/2", IsNumeric will say that it is not numeric because the forward slash is not considered a numeric by IsNumeric. Some might consider this a weakness. Other examples can also be identified, such as the factorial sign !, brackets, and braces. On the other hand, parentheses are considered numeric, so I think there is some judgment calls going on here.

    Just my $0.02.
    Live life to the fullest!!

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: If text in textbox is not numeric then..

    Code Doc is correct. A one size fits all approach through IsNumeric() is not always appropriate because of the way the function works, e.g. "2E5" returns True but that isn't so for an IP address octet or a cash amount. And newprogram, "1//2" should not be a valid expression.
    Last edited by leinad31; Feb 25th, 2008 at 10:13 PM.

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