Multi-Dimensional Arrays 
Author Message
 Multi-Dimensional Arrays

Does "for each" loop work with multi-dimensional arrays?


Sat, 14 Dec 2002 03:00:00 GMT  
 Multi-Dimensional Arrays



Quote:
> Does "for each" loop work with multi-dimensional arrays?

Yes it does, but i don't know if it can iterate over 1 particular dimension.
A for each over a multi dimensional array prints all the array elements
seprately (0,1) then (1,1) then (1 ,0) etc.

Here is a small example:

Private Sub Command1_Click()
Dim MyArray As Variant
Dim i As Integer
Dim ArrayEntry As Variant 'For each - loop variable must be of type variant

    ReDim MyArray(1, 0) 'Declare as 2 dimensional array

    For i = 0 To 9
        ReDim Preserve MyArray(1, i)
        MyArray(0, i) = "Label" & Str(i)
        MyArray(1, i) = "Value" & Str(i)
    Next i

    For Each ArrayEntry In MyArray
        Debug.Print ArrayEntry 'Prints all the values of the array
consequetively
    Next ArrayEntry
End Sub

Greetings,

Maarten.



Tue, 31 Dec 2002 03:00:00 GMT  
 Multi-Dimensional Arrays
dim myArray (2,5)

for row = 0 to ubound(myArray,2)
  for col = 0 to ubound(myArray,1)
    myArray(col,row) = "R" & row & "C" & col
  next
next

s = ""
for each elm in myArray
  s = s & elm & vbCrLf
next

msgbox s

--
Michael Harris
MVP Scripting


Does "for each" loop work with multi-dimensional arrays?



Tue, 31 Dec 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Multi-dimensional arrays - I know, I know

2. Multi Dimensional Arrays in Jscript (ASP)

3. Length of Multi-Dimensional Array

4. Passing Multi-Dimensional arrays to COM objects from VBScript/ASP

5. multi dimensional array

6. Multi-Dimensional Array?

7. Multi-dimensional arrays

8. multi-dimensional arrays

9. ReDim Preserve error with multi-dimensional array

10. Sort a multi-dimensional array in VBScript? (ASP)

11. Multi-dimensional Array()

12. Multi -dimensional array using VBS and WSH

 

 
Powered by phpBB® Forum Software