The information in this article applies to:
- Standard, Professional, and Enterprise Editions of Microsoft
Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
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.
MORE INFORMATION
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.
Create the Server Application
- Start a new project in Visual Basic. Form1 is created by default.
- 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
- Add two command buttons (Command1 and Command2) and a ComboBox to Form1.
- Add the following code to the Command1_Click event procedure:
Private Sub Command2_Click()
Call localcheck(Combo1)
End Sub
- 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
- Run PROJECT1.EXE from Program Manager or File Manager.
- 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.
|