Android Question Getting the length of a multi-dimensional array

wonder

Expert
Licensed User
So I have the following (x, y) array:
B4X:
Dim MyArray(10, number_of_elements) as Int
Where the number of elements is defined by the user.

When using the MyArray.Lenght property, I get the number 10.
How to get the lenght of the array's Y dimension through .lenght?
 

wonder

Expert
Licensed User

eurojam

Well-Known Member
Licensed User
Wonder,
there is no magic within this code. It uses the possibility of java called reflection which let you examine java classes at runtime, but this you already knows. And it is not my code, "big brother" google found it for me....but thanks for the honor;)

stefan
 

RB Smissaert

Well-Known Member
Licensed User
Try
B4X:
Dim MyArray(10, 20) As Int
Dim r As Reflector
Dim dims(0) As Int
r.Target = MyArray
dims = r.TargetRank
Log("array dimension: " & dims.Length & " Bounds " & dims(0) & " " & dims(1))
B4X:
Sub GetArrayInfo(oArray As Object) As Int()

Dim i As Int
Dim r As Reflector
Dim dims() As Int

r.Target = oArray
 dims = r.TargetRank
 Dim arrInt(dims.Length + 1) As Int
arrInt(0) = dims.Length

For i = 0 To dims.Length -1
arrInt(i + 1) = dims(i)
Next

Return arrInt

End Sub
RBS
 
Top