How to pass Collection object from VBScript to .NET -
07-06-2005
, 04:12 AM
Good Day
Overview
I need to call a .NET object's functions within VBScript and pass a VBScript
collection into this function call.
My VBScript receives a Collection object consisting of Recordsets. I want to
pass this Collection object from VBScript to my .NET object's function. Below
are the relevant code fragments from VBScript and .NET. I’ve added all
necessary references.
--------------------------------------------------------
VBScript
--------------------------------------------------------
Function Process(Inputs as Collection) as ADODB.Recordset
Dim a
Set a = CreateObject("Test.TestObj")
Set Process = a.funcReturnRS(Inputs)
End Function
--------------------------------------------------------
..NET
--------------------------------------------------------
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports ADODB
Imports VBA
Namespace Test
<Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)> _
Public Interface ITestObj
<DispId(5)> Function funcReturnRS(ByVal inp As VBA.Collection) As
ADODB.Recordset
End Interface
<ProgId("Test.TestObj"), _
ClassInterface(ClassInterfaceType.None), _
Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")> _
Public Class TestObj
Implements ITestObj
Public Function funcReturnRS(ByVal inp As VBA.Collection) As ADODB.Recordset
Implements ITestObj.funcReturnRS
Return inp
End Function
The Problem
The code above doesn’t behave as expected. I can pass a single recordset
(with e.g. Inputs.Item(2)) from VBScript, but I cannot pass a whole
Collection object to .NET.
I receive the error “Invalid procedure call or argument: a.funcReturnRS”
when I try to. Is there any way to do this? I’ve already tried adding the
Collection contents to an ArrayList and Dictionary object with the same
results. Using an Array is out of the question because Inputs are dynamic
data. |