Microsoft KB Archive/223111

= FIX: Type Mismatch Error When Compiling UserControl =

Article ID: 223111

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q223111



SYMPTOMS
An ActiveX DLL that references an ActiveX Usercontrol that has been compiled more than nine times will generate the following run-time error:

Run-time Error '13': Type Mismatch



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3.

For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed



Steps to Reproduce Behavior
 Create a new ActiveX Control project in Visual Basic. UserControl1 is created by default. Save and compile UserControl1 as Project1.OCX. On the Project menu, click Project1 Properties. Click the Component tab and confirm that Version Compatibility is set to Project Compatibility. On the File menu, click Add Project. Select ActiveX DLL in the Add Project dialog and click OK. (This will create a project group). On the Project menu, click Components. Check the Project1 VBP you just created and click OK.  Add the following code to the General Declarations section of Class1: Option Explicit

' local object reference to the ActiveX Usercontrol Private WithEvents ctlUserControl As Project1.UserControl1

Public Sub InitControl(ctlControl As Object)

' create a local reference to the Usercontrol that ' is passed in through this method. This is where ' the run-time error will be generated. Set ctlUserControl = ctlControl ' display a dialog that the reference was set properly MsgBox "ActiveX Usercontrol Reference Was Set", vbOKOnly, "ActiveX DLL Message" End Sub </li> Save and compile the Project Group.</li> Create a new Standard EXE Project. Form1 is created by default.</li> On the Project menu, click Components. Check the Project1 ocx you just created and click OK.</li> Site a copy of UserControl1 onto the default form (Form1).</li>  Add the following code to the General Declarations section of Form1: Option Explicit

' local object reference to the ActiveX DLL object Private cTestServer As Object

Private Sub Form_Load

' create an instance of the ActiveX DLL Object Set cTestServer = CreateObject("Project2.Class1") ' call a method of the object, passing in the usercontrol cTestServer.InitControl UserControl11 End Sub </li> Press the F5 key to run the project. The project will load and run without error.</li> Save and compile the Standard EXE.</li> Open the Project Group that contains the ActiveX DLL and ActiveX Usercontrol.</li> Compile the Project Group ten (10) times.</li> Open the Standard EXE project.</li> Press the F5 key to run the project. The run-time error will be generated.</li></ol>

Keywords: kbbug kbfix kbctrlcreate kbcompiler kbvs600sp3fix KB223111

-

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

© Microsoft Corporation. All rights reserved.