-
ErrorProvider?
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
-
Re: ErrorProvider?
The ErrorProvider must have been added to the form in the designer, which generates the declaration in the designer code file. If you right-click on the variable name and select Go To Definition then the IDE should open that code file and you can see the code generated in response to your actions in the designer. You can also click Show All Files in the Solution Explorer and then expand your form's node you'll get access to the designer code file.
-
Re: ErrorProvider?
You are absolutely right!
Form1.Designer.vb shows up and it is declared in this file.
If its not to lengthy, would the originator of the program have written this file or is it generated by VB? By the way, I see you have overreached &HFFFF Posts thanks for all of your responses!
Edit: I see the same file in programs I have written so it must be generated by VB.
I would then conclude the originator would have added the declaration himself, something I would think is a no no.