C
Carl Revell
Please note: The example below refers to .NET code, but I think the issue is
VBScript/COM/Array/Variant related, hence my posting in this Newsgroup
rather than a .NET one.
I am trying to get a simple (for now) ASP page working with a .NET class
registered for COM Interop. I've done this before successfully but have run
into a problem with a function in my .NET component which takes an Array as
a parameter. The functionality of the following code is purely to show the
issue - it doesn't do anything "useful" at all.
Here's the very simple .NET class code...
Public Class Class1
Public Function Names(ByVal theArray() As Object) As String
Dim i As String
For Each i In theArray
Names &= i & " "
Next
Return Names
End Function
End Class
This simply takes an array (of strings ultimately) and returns them as one
string, separated by a space.
Here are two examples of simple ASP to call the component that all fail with
an error (see below)
' Example 1 - FAILS
Dim myObj : Set myObj = Server.CreateObject("InteropTest.Class1")
Dim myArray(2)
myArray(0) = "Tom"
myArray(1) = "Dick"
myArray(2) = "Harry"
Response.Write myObj.Names(myArray)
' Example 2 - FAILS
Dim myObj : Set myObj = Server.CreateObject("InteropTest.Class1")
Dim myArray
myArray = Array("Tom","Dick","Harry")
Response.Write myObj.Names(myArray)
Both fail with this error:-
a.. Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'Names'
/InteropTest/InteropTest/InteropTest.asp, line 24
However, THIS version of the ASP works fine!?!?!
' Example 3 - WORKS
Dim myObj : Set myObj = Server.CreateObject("InteropTest.Class1")
Response.Write myObj.Names(Array("Tom","Dick","Harry"))
Somehow, if I copy Array("Tom","Dick","Harry") to a variable first, the
function call fails but if I pass Array("Tom","Dick","Harry") directly as
the function parameter it works!?!? Duh!
Q. "Why don't you just use the version that works then...?"
A. I'm trying to pass an array returned by the ADO RecordSet GetRows()
method to the .NET class method and, unfortunately, it behaves like the
first two examples - it fails.
Any help very much appreciated!
Thanks,
Carl
VBScript/COM/Array/Variant related, hence my posting in this Newsgroup
rather than a .NET one.
I am trying to get a simple (for now) ASP page working with a .NET class
registered for COM Interop. I've done this before successfully but have run
into a problem with a function in my .NET component which takes an Array as
a parameter. The functionality of the following code is purely to show the
issue - it doesn't do anything "useful" at all.
Here's the very simple .NET class code...
Public Class Class1
Public Function Names(ByVal theArray() As Object) As String
Dim i As String
For Each i In theArray
Names &= i & " "
Next
Return Names
End Function
End Class
This simply takes an array (of strings ultimately) and returns them as one
string, separated by a space.
Here are two examples of simple ASP to call the component that all fail with
an error (see below)
' Example 1 - FAILS
Dim myObj : Set myObj = Server.CreateObject("InteropTest.Class1")
Dim myArray(2)
myArray(0) = "Tom"
myArray(1) = "Dick"
myArray(2) = "Harry"
Response.Write myObj.Names(myArray)
' Example 2 - FAILS
Dim myObj : Set myObj = Server.CreateObject("InteropTest.Class1")
Dim myArray
myArray = Array("Tom","Dick","Harry")
Response.Write myObj.Names(myArray)
Both fail with this error:-
a.. Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'Names'
/InteropTest/InteropTest/InteropTest.asp, line 24
However, THIS version of the ASP works fine!?!?!
' Example 3 - WORKS
Dim myObj : Set myObj = Server.CreateObject("InteropTest.Class1")
Response.Write myObj.Names(Array("Tom","Dick","Harry"))
Somehow, if I copy Array("Tom","Dick","Harry") to a variable first, the
function call fails but if I pass Array("Tom","Dick","Harry") directly as
the function parameter it works!?!? Duh!
Q. "Why don't you just use the version that works then...?"
A. I'm trying to pass an array returned by the ADO RecordSet GetRows()
method to the .NET class method and, unfortunately, it behaves like the
first two examples - it fails.
Any help very much appreciated!
Thanks,
Carl