FIX: Type Mismatch Error When Compiling UserControl
ID: Q223111
|
The information in this article applies to:
-
Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 6.0
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 this to be a bug in the Microsoft products 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:
Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why
Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed
MORE INFORMATION
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
-
Save and compile the Project Group.
-
Create a new Standard EXE Project. Form1 is created by default.
-
On the Project menu, click Components. Check the Project1 ocx you just created and click OK.
-
Site a copy of UserControl1 onto the default form (Form1).
-
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
-
Press the F5 key to run the project. The project will load and run without error.
-
Save and compile the Standard EXE.
-
Open the Project Group that contains the ActiveX DLL and ActiveX Usercontrol.
-
Compile the Project Group ten (10) times.
-
Open the Standard EXE project.
-
Press the F5 key to run the project. The run-time error will be generated.
Additional query words:
Keywords : kbActiveX kbCompiler kbCtrlCreate kbVBp600bug kbGrpVB kbVS600sp3fix
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbbug