Microsoft KB Archive/129942

= PRB: Using TypeOf as Part of an If Statement Fails =

Article ID: 129942

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition

-



This article was previously published under Q129942



SYMPTOMS
Using TypeOf as part of an If statement fails when it is used it on a control that was passed to a server application.



CAUSE
To resolve the type of an object through the TypeOf interface, remoting is required for the actual control type. However, there is no remoting capability for controls.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
Develop and run a container and a server application:

Create the Container Application
 Start a new project in Visual Basic. Form1 is created by default. From the Insert menu, choose Class Module to add Class1 to the project.  Set the properties of Class1 as follows:   Property      Value Instancing   1-Creatable SingleUse Name         Class1 Public       True   Add the following code to the general declarations section of Class1: Public Sub DataLoadList(c) If TypeOf c Is ComboBox Then MsgBox "ComboBox" Else MsgBox "Not a ComboBox" End If  End Sub  From the File menu, choose Make EXE File, and name the executable as Project1.</li></ol>

Create the Server Application
<ol> Start a new project in Visual Basic. Form1 is created by default.</li>  Add the following code to the general declarations section of Form1: Private Sub localcheck(c) If TypeOf c Is ComboBox Then MsgBox "ComboBox" Else MsgBox "Not a ComboBox" End If  End Sub </li> Add two command buttons (Command1 and Command2) and a ComboBox to Form1.</li>  Add the following code to the Command1_Click event procedure: Private Sub Command2_Click Call localcheck(Combo1) End Sub </li>  Add the following code to the Command2_Click event procedure: Private Sub Command1_Click Dim x As Object Set x = CreateObject("Project1.Class1") Call x.DataLoadList(Combo1) Set x = Nothing End Sub </li> Run PROJECT1.EXE from Program Manager or File Manager.</li> Run Project2 from the Visual Basic design environment. Click the Command1 button for a local check of the TypeOf statement. The message "ComboBox" is displayed in a message box. Click the Command2 button to test the TypeOf statement across processes and the message "Not a ComboBox" is displayed in a message box.</li></ol>

Additional query words: 4.00 vb4win vb4all

Keywords: kbprb KB129942

-

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

© Microsoft Corporation. All rights reserved.