472,805 Members | 1,210 Online

# Array of Arrays

Hi there,

How to dim a array of arrays and index it? Let's say,
array of 10 elements with each element is a (8, 12) 2-D

Hugh
Nov 21 '05 #1
5 1331

"Hugh" <an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
Hi there,

How to dim a array of arrays and index it? Let's say,
array of 10 elements with each element is a (8, 12) 2-D

Hugh

Have u tried 'Dim intArray(8, 12)() As Integer'?

Hope this helps :)

Mythran
Nov 21 '05 #2
Hugh,
Try something like:

Dim elements(10 - 1)(,) As Integer
Note you need to explicitly initialize each element of the array:

For index As Integer = 0 To elements.Length - 1
ReDim elements(index)(8 - 1, 12 - 1)
Next

To initialize every element of the inner arrays, you can use something like:

Dim rng As New Random
For index As Integer = 0 To elements.Length - 1
Dim element(,) As Integer = elements(index)
For row As Integer = element.GetLowerBound(0) To
element.GetUpperBound(0)
For column As Integer = element.GetLowerBound(1) To
element.GetUpperBound(1)

element(row, column) = rng.Next(1, 10)
Next
Next
Next

Remember that arrays are reference types, so element refers to the specific
inner array, not a copy of the inner array...

Alternatively you can access one of the inner array elements directly:

elements(index)(row, column) = rng.Next(1, 10)

Hope this helps
Jay

"Hugh" <an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
Hi there,

How to dim a array of arrays and index it? Let's say,
array of 10 elements with each element is a (8, 12) 2-D

Hugh

Nov 21 '05 #3
Mytrhan,
Wouldn't that be a 2-D array of arrays of integers, as opposed to an array
of 2-D arrays of integers?

A 2-D array of arrays of integers:
Dim intArray(8, 12)() As Integer

A 10 element array of 2-D arrays of integers:
Dim elements(10 - 1)(,) As Integer

I'd be curious on which Hugh actually meant.

Jay

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:uC**************@tk2msftngp13.phx.gbl...

"Hugh" <an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
Hi there,

How to dim a array of arrays and index it? Let's say,
array of 10 elements with each element is a (8, 12) 2-D

Hugh

Have u tried 'Dim intArray(8, 12)() As Integer'?

Hope this helps :)

Mythran

Nov 21 '05 #4
Thank you very much, Jay and Mytrhan. What I wanted was a
10 elements of 1D array with each element is a 2D array.
I think Jay is right. Thank you again. I have been busy
at other things and have not had chance to try out yet.

Hugh

-----Original Message-----
Mytrhan,
Wouldn't that be a 2-D array of arrays of integers, as opposed to an arrayof 2-D arrays of integers?

A 2-D array of arrays of integers:
Dim intArray(8, 12)() As Integer

A 10 element array of 2-D arrays of integers:
Dim elements(10 - 1)(,) As Integer

I'd be curious on which Hugh actually meant.

Jay

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in messagenews:uC**************@tk2msftngp13.phx.gbl...

"Hugh" <an*******@discussions.microsoft.com> wrote in message news:0e****************************@phx.gbl...
Hi there,

How to dim a array of arrays and index it? Let's say,
array of 10 elements with each element is a (8, 12) 2-D

Hugh

Have u tried 'Dim intArray(8, 12)() As Integer'?

Hope this helps :)

Mythran

.

Nov 21 '05 #5

"Hugh" <an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl...
Thank you very much, Jay and Mytrhan. What I wanted was a
10 elements of 1D array with each element is a 2D array.
I think Jay is right. Thank you again. I have been busy
at other things and have not had chance to try out yet.

Hugh

Glad I didn't gamble anything :)

Mythran
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.