KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

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

Article: Q129942
Product(s): Microsoft Visual Basic for Windows
Version(s): 4.0
Operating System(s): 
Keyword(s): 
Last Modified: 02-NOV-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual Basic Standard Edition for Windows, version 4.0 
- Microsoft Visual Basic Professional Edition for Windows, version 4.0 
- Microsoft Visual Basic Enterprise Edition 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
--------------------------------

1. Start a new project in Visual Basic. Form1 is created by default.

2. From the Insert menu, choose Class Module to add Class1 to the project.

3. Set the properties of Class1 as follows:

  Property      Value
  ------------------------------------
  Instancing    1-Creatable SingleUse
  Name          Class1
  Public        True

4. 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

5. From the File menu, choose Make EXE File, and name the executable as
  Project1.

Create the Server Application
-----------------------------

1. Start a new project in Visual Basic. Form1 is created by default.

2. 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

3. Add two command buttons (Command1 and Command2) and a ComboBox to Form1.

4. Add the following code to the Command1_Click event procedure:

     Private Sub Command2_Click()
        Call localcheck(Combo1)
     End Sub

5. 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

6. Run PROJECT1.EXE from Program Manager or File Manager.

7. 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.

Additional query words: 4.00 vb4win vb4all

======================================================================
Keywords          :  
Technology        : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB400Search kbVB400
Version           : :4.0
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 1986-2002.