HOWTO: Implement Array Arguments in Visual Basic COM Objects for Active Server Pages

ID: Q217114


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


SUMMARY

This article describes, by example, how to implement arrays to be passed as parameters from Active Server Pages (ASP) to a Visual Basic COM Object.

It is important to keep in mind that array arguments for methods must be declared as variant data type and must the passed by reference. Declaring an array argument as any other type may generate one of the following errors:


error 'ASP 0115' - A trappable error occured in an external object
-or-
Invalid procedure call or argument
-or-
Type Mismatch
-or-
Object Does not Support This property or method


MORE INFORMATION

Use the following steps to implement arrays to be passed as parameters from (ASP) to a Visual Basic COM Object:

  1. Create a Visual Basic ActiveX Dll project called ASPArray.


  2. Change the name of the class module to clsArray.


  3. Implement the following function:
    
    Public Function TestArray( ByRef vArray as Variant ) as String
      Dim nCnt as integer
    
      'Check that the argument passed is an array
      If Not IsArray( vArray ) Then
        TestArray = "Parameter is not an Array"
        Exit Function
      End If
    
      For nCnt = LBound(vArray) to UBound(vArray)
          'Traverse Array Element        
      Next nCnt
        
      TestArray = "Parameter is an Array"
    End Function 


  4. Create an ASP page with the following code:
    
    <%
      Dim oTestObj, vMyArray(2), vRtnValue
            
      vMyArray(0) = "Element 1"
      vMyArray(1) = "Element 2"
      vMyArray(2) = "Element 3"
    
      Set oTestObj = Server.CreateObject("ASPArray.clsArray")
      vRtnValue = oTestObj.TestArray( vMyArray )
      Response.Write( "Return Value = " & vRtnValue )
    %>   


Additional query words:

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


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