Microsoft KB Archive/814329

= BUG: &quot;Event '' cannot be found&quot; error when you upgrade a Visual Basic 6.0 project to Visual Basic .NET =

Article ID: 814329

Article Last Modified on 3/20/2006

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition

-





SYMPTOMS
When you upgrade a Microsoft Visual Basic 6.0 project with a user control that has user-defined events to Microsoft Visual Basic .NET, you may receive the following error:

Event ' ' cannot be found.



CAUSE
The error occurs only if you use Visual Basic .NET reserved words as event names. For example, if you have a custom event named Controls in Visual Basic 6.0, and you upgrade the project to Visual Basic .NET by using Visual Basic Upgrade Wizard, you receive the following error message:

Event 'Controls' cannot be found.

When the Wizard tries to upgrade the Visual Basic 6.0 project to Visual Basic .NET, it encounters a conflict. The conflict occurs because Controls is a reserved word that you use as an event name. Therefore, the Wizard renames the declaration of the Controls event to Controls_Renamed, and tries to call the Controls_Renamed event handler when the event is raised. However, the Wizard does not rename the event handler that handles the Controls event to Controls_Renamed. Therefore, you receive the compilation error.



WORKAROUND
To work around this problem, rename the event in the event handler method, as follows:

Change Private Sub UserControl11_Controls(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles UserControl11.Controls to Private Sub UserControl11_Controls(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles UserControl11.Controls_Renamed



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.  This bug does not apply to Microsoft Visual Basic .NET (2002).



Steps to Reproduce the Behavior
 Open Microsoft Visual Basic 6.0, and then create a new Standard EXE project. On the Project menu, point to Add User Control, and then click Open.

UserControl1 is added to the project. Select Usercontrol1, and then click Code on the View menu.  Add the following code to UserControl1.vb. Event Controls Public Sub Procedure1 RaiseEvent Controls End Sub  Save, and then close the UserControl1 designer.</li> On the toolbox, double-click UserControl1.

By default, UserControl11 is added to the form.</li> Click to select Form1.</li> On the View menu, click Code.</li>  Add the following code: Private Sub Form_Load UserControl11.Procedure1 End Sub

Private Sub UserControl11_Controls MsgBox (&quot;Hello World&quot;) End Sub </li> Save the project, and then exit Visual Basic 6.0.</li> Start Visual Studio .NET 2003.</li> On the File menu, click Open, and then click Project.</li> Click to select Project1.vbp, and then click Open to activate Visual Basic Upgrade Wizard.</li> Click Next on each page of the Wizard to move to the next page. Click Yes when you are prompted to create a new folder for the project.</li> On the Build menu, click Build Solution. Click Save when you are prompted to save Project1.sln.

You receive the error mentioned in the &quot;Symptoms&quot; section of this article.

</li></ol>

Keywords: kbbug kbupgrade kbmigrate kbwizard kbctrl kbcontrol kbevent kbvs2005swept kbvs2005doesnotapply KB814329

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.