It may not be tidy but I am trying to fine tune the code below to handle validation.
It works great at keeping anything but numbers from being entered in either TextBox. I need some suggestions / examples if possible on how to force input in both boxes.Code:Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar.IsNumber(e.KeyChar) = False Then e.Handled = True End If End Sub Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress If e.KeyChar.IsNumber(e.KeyChar) = False Then e.Handled = True End If
Example: When my form loads it places focus on TextBox1 and the user must enter a number in TextBox1 and then tab over to TextBox2 and place another number in it before they will be allowed to click a button that runs another function in the form. If they don't put input in both TextBoxes I need a MessageBox to show that reminds them to enter numbers in both TextBoxes before they can click any other buttons on the form.
As always, much thanks for replies.![]()




Reply With Quote