468,121 Members | 1,443 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,121 developers. It's quick & easy.

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
array. Thanks in advance for your help.

Hugh
Nov 21 '05 #1
5 1178

"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
array. Thanks in advance for your help.

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
array. Thanks in advance for your help.

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
array. Thanks in advance for your help.

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
array. Thanks in advance for your help.

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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by simkn | last post: by
21 posts views Thread by yeti349 | last post: by
104 posts views Thread by Leszek | last post: by
24 posts views Thread by Michael | last post: by
57 posts views Thread by buuuuuum | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
18 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.