PRB: Passing Parameters By Reference to a VB COM Object

ID: Q197956


The information in this article applies to:
  • Active Server Pages
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
  • Microsoft Internet Information Server versions 4.0, 5.0


SYMPTOMS

When passing a parameter to a COM Component's method in Active Server Pages (ASP), the following error occurs:

Microsoft VBScript runtime error '800a000d' Type mismatch

Or the value stored in the variable passed to the method is not changed.


CAUSE

VBScript will pass parameters to a method by value if the argument's data type is NOT declared as a variant and the parameter is passed by reference if the argument's data type is declared as variant by the method.


RESOLUTION

Parameters to be passed by reference to a method should always be declared as a variant data type by the method, while parameters to be passed by value can be declared as any type by the method.


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a Visual Basic ActiveX DLL Project called "ByRefProj."


  2. Add class module called "ByRefObj."


  3. Implement the following method:
    
    Public Sub ByRefMethod( ByRef strVal as String )
      strVal = "This variable is passed by Reference"
    End Sub 


  4. Create an ASP Page that calls this Method:
    
    <%
      Dim objTest, strByRefVal
      Set objTest = Server.CreateObject("ByRefProj.ByRefObj")
      objTest.ByRefMethod strByRefVal
    %> 


  5. Run ASP. The following error occurs:
    Microsoft VBScript runtime error '800a000d'
    Type mismatch: 'ByRefMethod'


To correct this behavior:

Change the implementation of the method ByRefMethod as follows:

Public Sub ByRefMethod( ByRef strVal as Variant )
  strVal = "This variable is passed by Reference"
End Sub 

Additional query words:

Keywords : kberrmsg kbASP kbCOMt KbVBA kbVBp600 kbVBScript kbGrpASP kbCodeSnippet kbiis400 kbiis500
Version : WINDOWS:5.0,6.0; winnt:
Platform : WINDOWS winnt
Issue type : kbprb


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.