For the record .....
Subs and multi-dimensional arrays
The trick with multi-dimensional arrays is knowing when - and when not - to use explicit dimension sizes.
To pass a multi-dimensioned array into a Sub you
could use this syntax:
Sub dbgIn(p(,) As String)
Log(p(1,1))
End Sub
which will work but it is clear that it is unsafe because the Log line is guessing the dimensions.
So will this work ?
Sub dbgIn(p(2,2) As String)
Log(p(1,1))
End Sub
No it won't - as the Intellisense help for Subs says - we can't pass explicit dimensions. We'll get an
"Object reference not set to an instance of an object" error. Instead, we need to use the 'lonely comma/s' syntax but check the dimensions before accessing the array. Unfortunately, we have to use the Reflection library (or dig into the Java) to get them. We can do something like this:
Sub dbgIn(p(,) As String)
Dim r As Reflector
Dim dims(0) As Int
r.Target = p
dims = r.TargetRank
If dims(0)>=1 And dims(1)>=1 Then
Log(p(1,1))
End If
End Sub
which will work and is safer.
To do the reverse and return a multi-dimensional array from a Sub we can do this:
Sub dbgOut As String(,)
Public strArr(2,2) As String
strArr(1,1) = "Out world!"
Return strArr
End Sub
This example creates a 2D array within the Sub and returns it from the sub. Note that you must explicitly declare the array dimensions when you create it within the body of the Sub - using a lonely comma will cause an error when you try to access it.
To access the returned array you can do this:
Dim dout(,) As String = dbgOut
Log(dout(1,1))
or you can also simply do this:
I hope this might be helpful.