|
I have a sample program that takes in change (money) amounts and converts them into the largest denominations possible (I teach VB.NET at a college and I made it up for my students to do). I am using the error provider to validate the input in each text box. Unfortunately, I have to duplicate the code for the validating event for each text box and change the control name to the particular text box. Is there any way to place this code in a procedure and let it handle the validating events for all of the text boxes? I want to leave option strict on so it won't allow me to late bind. Any info you can provide would be greatly appreciated.
Paul Norrod.
Here is my current code for the validating event for one of the text boxes (I can't retain my tabs in this thing - sorry):
Private Sub txtQuartersIn_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtQuartersIn.Validating
If Not IsNumeric(txtQuartersIn.Text) Then erpValidateInput.SetError(txtQuartersIn, "A non-numeric value was entered - Please correct") e.Cancel = True Else If CDec(txtQuartersIn.Text) < 0 Or CDec(txtQuartersIn.Text) > 10000 Then erpValidateInput.SetError(txtQuartersIn, "The value entered must be between 1 and 10,000 - Please correct") e.Cancel = True Else If CDec(txtQuartersIn.Text) <> CInt(txtQuartersIn.Text) Then erpValidateInput.SetError(txtQuartersIn, "Decimal values are not permitted - Please correct") e.Cancel = True Else erpValidateInput.SetError(txtQuartersIn, "") End If End If End If
End Sub |