472,805 Members | 1,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
7
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.