Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Multi-Dimensional Arrays Help required

Status
Not open for further replies.

BigM

Programmer
Aug 30, 2000
39
GB
Hi,

I have a 2 dimensional array which i would like to process with the "For Each Item in ArrayName....." as below.

Dim Item
Dim ArrayName(2,3)

ArrayName (0,0) = "Hello"
ArrayName (0,1) = "Fred"
ArrayName (0,2) = "Burt"
ArrayName (1,0) = "Goodbye"
ArrayName (1,1) = "Fred"
ArrayName (1,2) = "Burt"

For Each Item In ArrayName
etc etc

My Question is how do I process the second element of the array from here. The output I am trying to achieve would be

"Hello Fred Burt"
"Goodbye Fred Burt"

Thanks


 
Try using indexes instead of "for each ..."

Like this:

i = 1
for i = 1 to 3 ' Ubound (ArrayName)
write ArrayName (0,i)
next i


In the preceding case only the second index varies, you can also use this algorithm with the first index.
 
Small correction

'i = 1 There is no reason to preset i = 1
for j = 0 to 1 'for two messages you need another iteration
for i = 0 to 2 'The Ubound (ArrayName) = 3 but arrayname(0,3) has no data
write ArrayName (j,i) & " "
next i
write vbCrLf 'Line feed or &quot;<br&quot; for html script
next j

result ->
&quot;Hello Fred Burt &quot;
&quot;Goodbye Fred Burt &quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top