Results 1 to 4 of 4

Thread: [RESOLVED] No ABC Chars!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    20

    Resolved [RESOLVED] No ABC Chars!

    Ok, I used this code to stop letters from being entered into a txtBox, could someone help me to change this so that Nums cannot be entered.....

    VB Code:
    1. Private Sub txtExponent_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
    2.         Handles txtExponent.KeyPress, txtInput.KeyPress
    3.         If e.KeyChar Like "[!a-zA-Z]" AndAlso Not e.KeyChar = ControlChars.Back Then
    4.             e.Handled = True
    5.         End If
    6.     End Sub
    7. End Class

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: No ABC Chars!

    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    2.         If Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar) Then
    3.             e.Handled = False
    4.         Else
    5.             e.Handled = True
    6.         End If
    7.     End Sub

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: No ABC Chars!

    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    2.         If Char.IsLetter(e.KeyChar) Then
    3.             'The character being entered is a letter.
    4.         ElseIf Char.IsDigit(e.KeyChar) Then
    5.             'The character being entered is a decimal digit.
    6.         ElseIf Char.IsControl(e.KeyChar) Then
    7.             'The character being entered is a control character.
    8.         End If
    9.     End Sub
    The Char type has some other useful methods you should familiarise yourself with also.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    20

    Re: [RESOLVED] No ABC Chars!

    Thank you "Again" people!

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