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];