Results 1 to 3 of 3

Thread: ErrorProvider?

  1. #1

    Thread Starter
    Member VB6 to Vb2010's Avatar
    Join Date
    Dec 2010
    Posts
    38

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member VB6 to Vb2010's Avatar
    Join Date
    Dec 2010
    Posts
    38

    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.
    Last edited by VB6 to Vb2010; Feb 5th, 2011 at 01:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width