Unknown dimension of an array

F

Fia

Hi

I wounder if there is a way to take an array as argument and then print the
array's element, without knowing it's dimensions.
I know how to do if I know the array's dimensions, but not a clue if I don't
know the array's dimensions.


Sub messBox1(ByVal arr)
Dim s As String = ""

Dim i, j As Integer

For i = 0 To arr.rank

If arr.rank = 1 Then

s = s + arr(i) + "\n"

Else

For j = 0 To arr.getupperbound(1)

s = s + arr(i, j) + " "

Next

s = s + vbCrLf

End If

Next

MsgBox(s)

End Sub

I hope someone can give me a clue.

Fia
 
M

Mark Hurd

Fia said:
Hi

I wounder if there is a way to take an array as argument and then
print the array's element, without knowing it's dimensions.
I know how to do if I know the array's dimensions, but not a clue if I
don't know the array's dimensions.


Sub messBox1(ByVal arr)
Dim s As String = ""

Dim i, j As Integer

For i = 0 To arr.rank

If arr.rank = 1 Then

s = s + arr(i) + "\n"

Else

For j = 0 To arr.getupperbound(1)

s = s + arr(i, j) + " "

Next

s = s + vbCrLf

End If

Next

MsgBox(s)

End Sub

I hope someone can give me a clue.

Fia

I believe you'll have to use Array.GetValue(ByVal ParamArray Indices()
As Integer) and generate the indices array yourself -- i.e. /don't/ use
the fact that it is a ParamArray.
 
F

Family Tree Mike

Fia said:
Hi

I wounder if there is a way to take an array as argument and then print
the array's element, without knowing it's dimensions.
I know how to do if I know the array's dimensions, but not a clue if I
don't know the array's dimensions.


Sub messBox1(ByVal arr)
Dim s As String = ""

Dim i, j As Integer

For i = 0 To arr.rank

If arr.rank = 1 Then

s = s + arr(i) + "\n"

Else

For j = 0 To arr.getupperbound(1)

s = s + arr(i, j) + " "

Next

s = s + vbCrLf

End If

Next

MsgBox(s)

End Sub

I hope someone can give me a clue.

Fia


First, I would turn Option Strict On. You should always declare your
parameter types.

Next, how about this routine:

Sub messBox2(ByVal arr As Object())
Dim s As String = ""
For Each obj As Object In arr
s = s & obj.ToString() & "\n"
Next
MsgBox(s)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top