Array and 800A005 Runtime Error

Discussion in 'ASP General' started by Carl Revell, Jan 6, 2004.

  1. Carl Revell

    Carl Revell Guest

    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
    Carl Revell, Jan 6, 2004
    #1
    1. Advertising

  2. Carl Revell

    Bob Barrows Guest

    Carl Revell wrote:
    > 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.
    >


    Have you tried
    Response.Write myObj.Names(rs.GetRows)

    Have you looked at these articles?
    http://support.microsoft.com/default.aspx?scid=kb;en-us;197956
    http://support.microsoft.com/default.aspx?scid=kb;en-us;244012
    http://support.microsoft.com/default.aspx?scid=kb;en-us;243548

    FWIW, that "Names" property/sub name sounds suspiciously like a reserved
    keyword (I may be wrong). It probably has nothing to do with your problem
    but I just thought I would mention it.


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows, Jan 6, 2004
    #2
    1. Advertising

  3. Carl Revell

    Carl Revell Guest

    Bob,

    Thanks for the response which proved very fruitful.

    The second article link you published
    (http://support.microsoft.com/default.aspx?scid=kb;en-us;244012) explained
    how if you wrap parameters in parentheses, they are first evaluated as an
    expression which can't then be passed ByRef and so is passed ByVal.

    So, this fails:-

    Dim myObj : Set myObj = Server.CreateObject( "InteropTest.Class1" )
    myArray = Array( "Tom", "Dick", "Harry" )
    Response.Write myObj.Names( myArray )

    and this (note extra parentheses around myArray) works!!!

    Dim myObj : Set myObj = Server.CreateObject( "InteropTest.Class1" )
    myArray = Array( "Tom", "Dick", "Harry" )
    Response.Write myObj.Names( ( myArray ) )

    Unbelievable!

    I assume that VBScript tries to pass myArray ByRef, but the variable myArray
    is already effectively a reference to the beginning of the array, so in
    effect it's passing the reference of a reference and the .NET component
    doesn't like it? I've tried declaring the method parameters as ByRef and
    ByVal (I've tried both although I don't need to change the original array in
    the method so ByVal is fine for me) but I still need to wrap the parameter
    in parentheses within the ASP script in order for it to work.

    Thanks again Bob, hopefully I can get on and finish the application now!

    Carl Revell

    > Have you tried
    > Response.Write myObj.Names(rs.GetRows)
    >
    > Have you looked at these articles?
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;197956
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;244012
    > http://support.microsoft.com/default.aspx?scid=kb;en-us;243548
    >
    > FWIW, that "Names" property/sub name sounds suspiciously like a reserved
    > keyword (I may be wrong). It probably has nothing to do with your problem
    > but I just thought I would mention it.
    >
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
    Carl Revell, Jan 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Polo Lee
    Replies:
    0
    Views:
    2,726
    Polo Lee
    Jul 7, 2003
  2. Yongsub Eric Shin
    Replies:
    7
    Views:
    862
    Martin
    Jan 14, 2004
  3. Hal Vaughan
    Replies:
    11
    Views:
    1,107
    Gordon Beaton
    May 22, 2006
  4. Tony Johansson
    Replies:
    0
    Views:
    480
    Tony Johansson
    Aug 13, 2005
  5. Mara Guida

    const and array of array (of array ...)

    Mara Guida, Sep 2, 2009, in forum: C Programming
    Replies:
    3
    Views:
    488
    David RF
    Sep 3, 2009
Loading...

Share This Page