' With acknowledgements to hellswraith (amended)
Amended 02/05/05 to clear textbox if non-numeric entry existing prior to first keypress.
VB Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim I As Integer = Convert.ToInt32(e.KeyChar) Select Case I Case 13 MessageBox.Show("Enter Key Pressed") Case 8 ' Allow Backspace-delete key Exit Sub Case Else If Not IsNumeric(TextBox1.Text) Then TextBox1.Text = "" End If If Not IsNumeric(TextBox1.Text & e.KeyChar) Then MessageBox.Show("Non Numeric Character entered - " & e.KeyChar) e.Handled = True End If End Select End Sub


Reply With Quote