Home : AutomationException: 0x800a0009 - Subscript out of range
Q96334 - HOWTO: AutomationException: 0x800a0009 - Subscript out of range

AutomationException: 0x800a0009 - Subscript out of range

 

You may get this message when passing a two dimensional array from Java to VB. For example:

VB

The VB code below takes a two dimensional array as the parameter:

Public Function passTwoDimArrayByRef(ByRef xyz() As Variant) As Boolean
   xyz(0, 0) = #10/10/2004#
   xyz(0, 1) = "Dan"
   xyz(0, 2) = 25
   xyz(1, 0) = #5/19/2004#
   xyz(1, 1) = "Am"
   xyz(1, 2) = 24
   passTwoDimArrayByRef = True
End Function

IDL

The above VB code will be converted into this IDL code:

[id(0x6003000a)]
HRESULT passTwoDimArrayByRef(
   [in, out] SAFEARRAY(VARIANT)* xyz,
   [out, retval] VARIANT_BOOL* );

Java

The code below is the way to access the VB method passTwoDimArrayByRef from Java:

   Object objArray[][][] = new Object[1][2][3];
   System.out.println(xyz.passTwoDimArrayByRef(objArray));

Note that the Java objArray is a three dimensional 1x2x3 array. The VB array xyz is a two dimensional 2x3 array, and therefore the second index of objArray can not be smaller than 2, and the third index of objArray can not be smaller than 3. The following definition of the Java objArray also works:

   Object objArray[][][] = new Object[1][3][4];

The following wrong definitions of the Java objArraywill all generate the error message AutomationException: 0x800a0009 - Subscript out of range:

   Object objArray[][] = new Object[2][3];
   Object objArray[][][] = new Object[1][1][3];
   Object objArray[][][] = new Object[1][2][2];

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 7/11/2006.
Last Modified by No Author Name Available!.
Article has been viewed 7199 times.
Rated 4 out of 10 based on 4 votes.
Print Article
Email Article