I have the following downloaded code example. It works as expected. Can someone tell me my it works without having to declare "Dim errBadDigits as New ErrorProvider" Rather when I insert this line I get "Error 1 'errBadDigits' is already declared as 'Friend WithEvents errBadDigits As System.Windows.Forms.ErrorProvider' in this class. C:\Users\test_2\Documents\Visual Studio 2010\Projects\FiveDigits\Form1.vb 11 9 FiveDigits", Where can I see this decloration? Friend WithEvents ?
Code:Public Class Form1 ' Validate a TextBox's contents. Private Sub txtNumber_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNumber1.Validating, txtNumber2.Validating, txtNumber3.Validating ' Get the TextBox. Dim text_box As TextBox = DirectCast(sender, TextBox) ' Validate the control's value. ValidateFiveDigits(text_box, e.Cancel) End Sub ' Verify that the TextBox contains five digits. Private Sub ValidateFiveDigits(ByVal text_box As TextBox, ByRef cancel_event As Boolean) If text_box.Text.Length = 0 Then ' Allow a zero-length string. cancel_event = False Else ' Allow five digits. cancel_event = Not (text_box.Text Like "#####") End If ' See if we're going to cancel the event. If cancel_event Then ' Invalid. Set an error. errBadDigits.SetError(text_box, " must contain exactly five digits") Else ' Valid. Clear any error. errBadDigits.SetError(text_box, "") End If End Sub End Class




Reply With Quote