if you write general function it's handy if you can retrieve both sizes.
below is an example.
usually my work grids are square but if they aren't the Y logic ain't right.
and using global variables there is kind of non logical.
B4X:
Sub printGrid(g(,) As Int)
Dim t As String
For y=0 To g.Length-1
For x=0 To g.Length-1
If x=0 Then
t=t & g(x,y)
Else
t=t & "," & g(x,y)
End If
Next
t=t & CRLF
Next
Log(t)
End Sub
I hoped that g(0).length would work but it doesn't
Dim mda(5,3) As Int
Dim Result As Map = GetDimensions(mda)
Log("Cols : " & Result.Get("Cols"))
Log("Rows : " & Result.Get("Rows"))
B4X:
Private Sub GetDimensions(A As Object) As Map
Dim Jo As JavaObject
Jo.InitializeStatic("java.util.Arrays")
Dim L As List = Jo.RunMethod("asList",Array(A))
Dim Cols As Int = L.Size
Dim A1() As Int = L.Get(0)
Dim Rows As Int = A1.Length
Return CreateMap("Cols":Cols,"Rows":Rows)
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.