DOCUMENT:Q190210 07-AUG-1998 [vbwin] TITLE :PRB: OCX Gives "Type Mismatch" or Does Nothing on Target Machine PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0,6.0 OPER/SYS:WINDOWS KEYWORDS: ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic for Windows Learning, Professional, and Enterprise Editions, versions 5.0, 6.0 --------------------------------------------------------------------- SYMPTOMS ======== An ActiveX component compiled in Visual Basic gives a Type Mismatch error after being installed on another computer. This occurs even if the Setup Wizard was used to install the OCX or if the OCX was properly registered using Regsvr32.exe. The control works perfectly on the development machine, but fails on other machines. Recompiling the UserControl on the target machine fixes the problem. Distributing the Control as part of an standard EXE application also works without error. -or- An ActiveX component compiled in Visual Basic does not seem to be executing methods when those methods are associated with controls outside of the ActiveX component. This occurs under the same circumstances as the first scenario. CAUSE ===== You are attempting to reference an ActiveX control that is external to your ActiveX component using an early bound Class Name. For example, passing a TreeView control into your control and attempting to set it to a variable declared as TreeView, or trying to determine if the object passed is of type TreeView. If the first case, a Type Mismatch error occurs. In the second case, the logical evaluation returns False when you expect it to return True. RESOLUTION ========== Type Mismatch Error ------------------- If possible, do not pass ActiveX controls to your components. If the component needs a specific control to function correctly, include that control as part of the component. If you must pass ActiveX controls to your component, do not attempt to use early binding to the external control. Component "Does Nothing" ------------------------ If your control has methods that do not seem to be functioning, you may have logical evaluations that are not returning the results you expect on the target machine. For example, the statement: If TypeOf passedControl is ImageList.... is evaluated to be False, even if the external control is an ImageList. Using the following statement removes the specific reference to the class name, and returns a result of True. If TypeName(passedControl) = "ImageList"... STATUS ====== This behavior is by design. MORE INFORMATION ================ Steps to Reproduce Behavior --------------------------- 1. Create a new ActiveX Control project in Visual Basic. UserControl1 is created by default. 2. Choose Components from the Project menu and check "Microsoft Windows Common Controls." 3. Add the following code to the UserControl: Dim m_tree As TreeView Public Property Set tree(obj As Object) ' you must use obj as a late bound object ' the next line causes the error Set m_tree = obj End Property 4. Change the project name to PassTree. 5. From the File Menu, choose Make PassTree.ocx. 6. Start a new Standard EXE project. Form1 is created by default. 7. Choose Components from the Project menu, and check "Microsoft Windows Common Controls." 8. Check PassTree, and click OK. PassTree is added to the Toolbox. 9. Add a instance of the TreeView control and the PassTree control to Form1. 10. Add a CommandButton to Form1, and insert the following code in the Command1_Click event: Set Me.UserControl11.Tree = Treeview1 11. Run the project and click the CommandButton. 12. You should not see an error message. 13. Copy the PassTree.ocx to another computer that has Visual Basic installed. 14. Register the OCX on the second computer. Command line would be similar to: Regsvr32.exe \PassTree.ocx 15. Repeat steps 6 - 11 on the second computer. 16. You should see Error 13. Type Mismatch error. 17. If desired, move the Source PassTree.ocx project to the second machine and compile PassTree.OCX. Repeat steps 6 - 11 or refresh the reference to PassTree.ocx and rerun the project. The control should no longer exhibit the error. REFERENCES ========== For additional information, please see the following topic in the Visual Basic 5.0 Books Online, or the Visual Basic 6.0 Online Help: TITLE: Data Types Allowed in Properties and Methods Additional query words: kbDSupport kbDSD kbVBp500 kbVBp600 kbVBp kbNoKeyWord ====================================================================== Version : WINDOWS:5.0,6.0 Platform : WINDOWS Issue type : kbprb ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.