R riclp New Member Licensed User Longtime User Jul 17, 2013 #1 Hi to all. I want to get the two lengths of a bidimensional array. As for example: Dim mat(10, 5) As Float Log(mat.Length) It returns 10. And if I want to get the 2nd dimension length: Dim mat(10, 5) As Float Log(mat(0).Length) Return error: "Invalid number of indices" I thought bidimensional arrays are arrays of arrays and you can get the 2nd dimension by getting an individual sub-array length. Has anybody any suggestion without resorting to create a specific Type to store the two lengths and the array? Thanx.
Hi to all. I want to get the two lengths of a bidimensional array. As for example: Dim mat(10, 5) As Float Log(mat.Length) It returns 10. And if I want to get the 2nd dimension length: Dim mat(10, 5) As Float Log(mat(0).Length) Return error: "Invalid number of indices" I thought bidimensional arrays are arrays of arrays and you can get the 2nd dimension by getting an individual sub-array length. Has anybody any suggestion without resorting to create a specific Type to store the two lengths and the array? Thanx.
Erel B4X founder Staff member Licensed User Longtime User Jul 18, 2013 #2 You can use Reflector to get an array from a multidimension array: Code: Copy Dim r As Reflector Dim arr(2, 10) As Int r.Target = arr Dim arr1() As Int = r.GetArray(Array As Int(0)) Log(arr1.Length) Upvote 0
You can use Reflector to get an array from a multidimension array: Code: Copy Dim r As Reflector Dim arr(2, 10) As Int r.Target = arr Dim arr1() As Int = r.GetArray(Array As Int(0)) Log(arr1.Length)
R riclp New Member Licensed User Longtime User Jul 18, 2013 #3 Yes, it works, even when the bidimensional matrix is of Float type. Code: Copy Sub cols(mat(,) As Float) As Int Dim r As Reflector r.Target = mat Dim arr1() As Float = r.GetArray(Array As Int(0)) Return arr1.Length End Sub But I´m not sure about the way "GetArray" works in this case. Is it that it returns the first "sub-array" in the bidimensional matrix by getting the first object referenced by an Int array whose first value is "0"? May asume is this the way it works? Thank you Upvote 0
Yes, it works, even when the bidimensional matrix is of Float type. Code: Copy Sub cols(mat(,) As Float) As Int Dim r As Reflector r.Target = mat Dim arr1() As Float = r.GetArray(Array As Int(0)) Return arr1.Length End Sub But I´m not sure about the way "GetArray" works in this case. Is it that it returns the first "sub-array" in the bidimensional matrix by getting the first object referenced by an Int array whose first value is "0"? May asume is this the way it works? Thank you
Erel B4X founder Staff member Licensed User Longtime User Jul 19, 2013 #4 Is it that it returns the first "sub-array" in the bidimensional matrix by getting the first object referenced by an Int array whose first value is "0"? May asume is this the way it works? Click to expand... Yes. Upvote 0
Is it that it returns the first "sub-array" in the bidimensional matrix by getting the first object referenced by an Int array whose first value is "0"? May asume is this the way it works? Click to expand... Yes.