Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Array and 800A005 Runtime Error

Reply
Thread Tools

Array and 800A005 Runtime Error

 
 
Carl Revell
Guest
Posts: n/a
 
      01-06-2004
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


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      01-06-2004
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...b;en-us;197956
http://support.microsoft.com/default...b;en-us;244012
http://support.microsoft.com/default...b;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.


 
Reply With Quote
 
 
 
 
Carl Revell
Guest
Posts: n/a
 
      01-07-2004
Bob,

Thanks for the response which proved very fruitful.

The second article link you published
(http://support.microsoft.com/default...b;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...b;en-us;197956
> http://support.microsoft.com/default...b;en-us;244012
> http://support.microsoft.com/default...b;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.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
exception(logic error and runtime error) Tony Johansson C++ 0 08-13-2005 03:16 PM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM



Advertisments