How do I pass an array byRef from an ASP Page to a VB.Net function

Posted on 2005-05-13
Medium Priority
Last Modified: 2008-02-01
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(Contacts(), 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.


Question by:BethMagown
  • 3
  • 2
LVL 33

Expert Comment

ID: 13998774
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.

Author Comment

ID: 13999071
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.

LVL 33

Accepted Solution

raterus earned 1500 total points
ID: 13999428
I never knew something like this is possible.  Since it is, I can see a potential problem.  A vb.net array and a vbscript array are two totally different things as far as how they are structured in memory.  When you pass it byref, vb.net is going to try it's best to "interpret" it, but you're asking a lot here.  What you can try is to use one of the collection types (like arraylist) to dynamically add the elements you want, all from vbscript, then pass this collection type to the vb.net function.  Something like this..

Dim ar
Set ar = Server.CreateObject("ArrayList") 'use whatever you use to hook up to .net functions

NumberOfContacts = AutoResponse.GetTasks(ar, sfUserName, sfPW)

I don't know if this will work for you though, your main question is to pass it byref (I guess you want to modify it in VB.net and have the changes reflect in ASP?), you may run into the type problem again, but it's worth a shot.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 23

Expert Comment

ID: 14002789
raterus, regasm registers .NET dlls as COM objects.

Author Comment

ID: 14035707
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.
LVL 33

Expert Comment

ID: 14035735
Glad you got something to work!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question