What you are asking to do is called input validation and there are several ways to do this. The major dfference in techniques it mainly where the validation ocurrs (how close to where the input is) and how easy the code is reused across the project.
The easiest but least flexible method is to test an input just before its used in the subroutine or function where it used. For example you may test a value before a division to make sure you do not divide by zero. This validation is the furthest away from where the user input it and its not very resuable as its burried in a dedicated code section
The next method uses two textbox events "Validating" & Validated
These events fire when the user moves away from the text box.
You would test the textbox text property for a non zeor number in the Validating event and if it passes the test you allow the user to move away from the text box. If the test fails the user is not allowed to move out of the text box. The validated event can be used to detect a fail validation and handle changing the text box background color and displaying message boxes.
Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Dim str As String
Dim num As Double
str = TextBox1.Text
num = Val(str)
If num = 0 Then
Me.TextBox1.BackColor = Color.Pink
e.Cancel = True 'abort leaving the textbox
MessageBox.Show("Enter a non zero number")
End If
End Sub
Private Sub TextBox1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
'the textbox has passed validation
'reset the background color
Me.TextBox1.BackColor = Color.White
End Sub
The final method is to evaluate each character entered to a text box as its entered by the user and prevent some types of key presses from being accepted. For example only letting numbers be entered into a numeric entry. You also need to test for certain other key presses like a back space or deletion to allow the user to correct the input if a mistake is made.
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
'e.KeyValue is the ASCII code of the key pressed by the user
'convert the key press to ASCII code and test
Select Case Asc(e.KeyChar)
Case 48 To 57
'allow ascii 48 to 57
'allow numbrs 0 to 9
Case 8
'allow a back space
Case Else
'invalid key pressed
'change it to a null to prevent showing it
e.KeyChar = ""
e.Handled = True
End Select
End Sub
In this last example you test each key that is pressed and test to see if it is a character that you will allow to be entered. In this example I am only allowing numbers and a backspace to be pressed. Any other keypress is converted to a null ("").
This just scratches the surface of validation techniques as you can test keypress at a form level for all controls on a form and use different validation functions depending upon what type of info you want entered.