Results 1 to 4 of 4

Thread: Exit Sub if string = number

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Exit Sub if string = number

    Hello,

    I have a text box and a command button, what is the code to make sure that the text of the text box is not a number when I click the command button?

  2. #2
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Exit Sub if string = number

    VB Code:
    1. Private Sub Command1_Click()
    2.     If IsNumeric(Text1.Text) = True Then
    3.          Exit Sub
    4.     End If
    5. End Sub

    This might be what you are looking for.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Exit Sub if string = number

    This will work if the number is greater than 0 only.

    VB Code:
    1. Private Sub Command1_Click()
    2.   If Val(Text1.Text) > 0 Then
    3.     MsgBox "Valid Number"
    4.   End If
    5. End Sub

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Exit Sub if string = number

    This will find a number anywhere within the textbox string.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim EachCharacter As String * 1
    3. Dim MyNumber As Integer
    4. Dim i As Long
    5.     For i = 1 To Len(Text1.Text)
    6.         EachCharacter = Mid(Text1.Text, i, 1)
    7.         If IsNumeric(EachCharacter) Then 'its a number
    8.            MsgBox "No numbers allowed"
    9.            Exit For
    10.         End If
    11.        
    12.     Next
    13. End Sub

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