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

Posted on 2005-05-13
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 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
    LVL 33

    Expert Comment

    hmm, are you sure you are using the right langugage with the right technology?  ASP pages support VBScript, not  From the looks of your error, you are programming ASP not

    Author Comment

    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

    I never knew something like this is possible.  Since it is, I can see a potential problem.  A array and a vbscript array are two totally different things as far as how they are structured in memory.  When you pass it byref, 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 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 and have the changes reflect in ASP?), you may run into the type problem again, but it's worth a shot.

    LVL 23

    Expert Comment

    raterus, regasm registers .NET dlls as COM objects.

    Author Comment

    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

    Glad you got something to work!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    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 ( Literal, only instead of starting and ending with w…
    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now