Is it possible to use the For Each loop for multi dimensional Arrays

• : Is it possible to use the For Each loop for multi dimensional Arrays
:

yes, see example-

[code]
Option Explicit

Dim a(1 To 2, 1 To 5) As String

Private Sub Command1_Click()
Dim i As Integer, j As Integer

For i = 1 To 2
For j = 1 To 5
'assign value to array
a(i, j) = CStr(i) & "," & CStr(j)
Next j
Next i

For i = 1 To 2
For j = 1 To 5
'show array value
MsgBox a(i, j)
Next j
Next i

End Sub
[/code]
• I don't think this is what he was asking for.
He was asking for the "For Each"-Syntax.

: : Is it possible to use the For Each loop for multi dimensional Arrays
: :

Yes, it is possible, but the solution contains a death-defying hack, which you as a beginner shouldn't even consider using it.

:
: yes, see example-
:
:
: [code]:
: Option Explicit
:
:
: Dim a(1 To 2, 1 To 5) As String
:
:
: Private Sub Command1_Click()
: Dim i As Integer, j As Integer
:
: For i = 1 To 2
: For j = 1 To 5
: 'assign value to array
: a(i, j) = CStr(i) & "," & CStr(j)
: Next j
: Next i
:
: For i = 1 To 2
: For j = 1 To 5
: 'show array value
: MsgBox a(i, j)
: Next j
: Next i
:
: End Sub
: [/code]:

------------------------------------------
Only stupidity of mankind and the universe
are infinite, but i'm not sure concerning
the universe. A. Einstein
• : I don't think this is what he was asking for.
: He was asking for the "For Each"-Syntax.
:
:
: : : Is it possible to use the For Each loop for multi dimensional Arrays
: : :
:
: Yes, it is possible, but the solution contains a death-defying hack,
: which you as a beginner shouldn't even consider using it.
:

Actually, the following (fairly simple) code (which doesn't seem hacked) seems to work:
[code]
Dim someArray() As [italic]SomeTypeHere[/italic]
Dim vEnumerator As Variant 'Must be Variant for For...Each to work!

'Fill someArray here
'...

For Each vEnumerator In someArray
'Do something with the element, for instance annoy the user
' with a Message Box
MsgBox vEnumerator
Next
[/code]

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry
• Yes, it could work in .NET, since in .NET all Datatypes are kind of an object, and the For-Each-Syntax works only for Objects.

: Actually, the following (fairly simple) code (which doesn't seem
: hacked) seems to work:
: [code]:
: Dim someArray() As [italic]SomeTypeHere[/italic]
: Dim vEnumerator As Variant 'Must be Variant for For...Each to work!
:
: 'Fill someArray here
: '...
:
: For Each vEnumerator In someArray
: 'Do something with the element, for instance annoy the user
: ' with a Message Box
: MsgBox vEnumerator
: Next
: [/code]:
:
:
: Best Regards,
: Richard
:
: The way I see it... Well, it's all pretty blurry

------------------------------------------
Only stupidity of mankind and the universe
are infinite, but i'm not sure concerning
the universe. A. Einstein