Results 1 to 1 of 1

Thread: Checking for Valid Numerical Entry on Each KeyPress

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Checking for Valid Numerical Entry on Each KeyPress

    ' With acknowledgements to hellswraith (amended)
    Amended 02/05/05 to clear textbox if non-numeric entry existing prior to first keypress.

    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    2.        
    3.         Dim I As Integer = Convert.ToInt32(e.KeyChar)
    4.         Select Case I
    5.             Case 13
    6.                 MessageBox.Show("Enter Key Pressed")
    7.             Case 8        ' Allow Backspace-delete key
    8.                 Exit Sub
    9.             Case Else
    10.                 If Not IsNumeric(TextBox1.Text) Then
    11.                     TextBox1.Text = ""
    12.                 End If
    13.                 If Not IsNumeric(TextBox1.Text & e.KeyChar) Then
    14.                     MessageBox.Show("Non Numeric Character entered  - " & e.KeyChar)
    15.                     e.Handled = True
    16.                 End If
    17.         End Select
    18.     End Sub
    Last edited by taxes; Oct 19th, 2005 at 09:24 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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