0

hello,
I want to enter only numbers or only alphabets in my text box in vb.net.
wat code should i use in the keypress event to solve this problem

Like in vb 6 we use key ascii what is the similar thing in vb.NET

PLS help its very imp and urgent

thank you

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by waynespangler
0
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim x As String = e.KeyChar.ToString
        Select Case x
            Case "a" To "z", " ", "0" To "9", "A" To "Z"
                '            'allows these keystrokes thru disallows all others
            Case Else
                e.Handled = True
        End Select
    End Sub
0

thanks a lot for ur help.
Everything is working fine but have a problem the back space key is also not working when we put this code.
How to make the backspace key work..
Pls reply asap
thankin you

0

please insert the if stat.. in code

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim x As String = e.KeyChar.ToString

If Asc(e.KeyChar) = 8 Then
Return
End If


Select Case x
Case "a" To "z", " ", "0" To "9", "A" To "Z"
' 'allows these keystrokes thru disallows all others
Case Else
e.Handled = True
End Select
End Sub

0

Sorry it took so long replying but my computer went down, bummer.
just add chr(8) at the end of the string
Case "a" To "z", " ", "0" To "9", "A" To "Z", Chr(8)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.