BethMagown
asked on
How do I pass an array byRef from an ASP Page to a VB.Net function
I have an asp page that needs to call a VB.NET function. I want to pass in an array, use the VB.net function to populate this array and then use the data back in the asp page.
My code looks like this:
VB.NET function:
Public Function getTasks(ByRef Contacts() As VariantType, ByVal sfUser As String, ByVal sfPW As String) As Integer
---code to populate the array, return an integer value that is the number of entries in the array.
ASP Page Code:
NumberOfContacts = AutoResponse.GetTasks(Cont acts(), sfUserName, sfPW)
This is the error I'm getting when I run:
Microsoft VBScript runtime error '800a0009'
Subscript out of range
When I change the function call to remove the parenthesis after the name of the array, I get this error message.
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'GetTasks'
I also tried coding the VB.NET function to declare the Contacts As String and I still get an error.
I pretty new at VB.NET so all the help you can give me will be very appreciated.
My code looks like this:
VB.NET function:
Public Function getTasks(ByRef Contacts() As VariantType, ByVal sfUser As String, ByVal sfPW As String) As Integer
---code to populate the array, return an integer value that is the number of entries in the array.
ASP Page Code:
NumberOfContacts = AutoResponse.GetTasks(Cont
This is the error I'm getting when I run:
Microsoft VBScript runtime error '800a0009'
Subscript out of range
When I change the function call to remove the parenthesis after the name of the array, I get this error message.
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'GetTasks'
I also tried coding the VB.NET function to declare the Contacts As String and I still get an error.
I pretty new at VB.NET so all the help you can give me will be very appreciated.
hmm, are you sure you are using the right langugage with the right technology? ASP pages support VBScript, not VB.net. From the looks of your error, you are programming ASP not ASP.net.
ASKER
Yes, We do this all the time. I create VB.NET functions. Register the .dll file on the server, and call the functions from the ASP page. I just use Server.CreateObject to refer to the VB.NET object. It works fine, except in this one instance where I'm trying to pass an array.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
raterus, regasm registers .NET dlls as COM objects.
ASKER
raterus, you were right. After questioning my boss some more (he was the one who told me to code it that way!), he agreed with you that ASP and VB.NET look at arrays differently and its really not possible to pass them byRef between ASP and VB.NET. So, I had to change my code to pass back a string from my VB.NET function and break it apart in my ASP code. Thanks for the help.
Glad you got something to work!