Microsoft KB Archive/194570

= PRB: TypeOf Operator Does Not Recognize Form Object =

Article ID: 194570

Article Last Modified on 5/13/2003

-

APPLIES TO


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

-



This article was previously published under Q194570



SYMPTOMS
You are passing an object to an ActiveX component, and attempting to use the TypeOf operator to determine if the passed object is a form. TypeOf returns False, even if the object is a form.



RESOLUTION
Do not pass or return forms, controls, or other private objects as method arguments of an ActiveX component or control. Such objects are not intended for use in this manner, even though such operations may have succeeded in previous versions of Visual Basic. See the REFERENCES section below for more information.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Start a new ActiveX DLL project in Visual Basic. Class1 is created by default. Change the name of the project to TypeOfTest. Change the name of Class1 to testClass.  Add the following code to testClass: Public Function TestForm(AnyForm As Object) As Boolean If TypeOf AnyForm Is Form Then TestForm = True Else TestForm = False End If     End Function  Run the project. Start a second instance of Visual Basic, and choose Standard EXE.</li> From the Project menu, add a reference for TestTypeOf.</li>  Add the following code to the code window of Form1: Private Sub Form_Click Dim objTest As TypeOfTest.testClass Set objTest = New testClass MsgBox "TypeOf results: " & objTest.testForm(Me) Set objTest = Nothing End Sub </li> Run the project, and click on Form1.</li> The message box should display False, indicating that the TypeOf operator did not recognize the passed object to be of type Form.</li></ol>

<div class="references_section">