473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Trouble with Multidimensional Array Looping.

I'm having problems with my code concerning a mulitdimensional array. Basically, I'm trying to create an array (arrTotal) which contains all of the data from 2 arrays (arrOne & arrTwo). Basically, they each contain data from Tables, and I just want to combine them into a single array which contains all of the info. Here's what I have so far, but I know something isn't right:


Dim i As Integer
Dim j As Integer

'This gives me the total upper boundaries of both arrays
ReDim arrTotal((UBound(arrOne, 1)) + (UBound(arrTwo, 1)))

'intCount2ndDimension contains the Total Number of 2nd Dimensions for
'both arrays
For j = 0 To intCount2ndDimension

'Here is where my problem is: I'm trying to fill in the data from both
'arrays into arrTotal, but I'm having problems with the multidimension
'Do I need to add both the 1st and 2nd dimensions separately or can I do it like below?:
For i = 0 To UBound(arrOne, 1)

arrTotal(i) = arrOne(i, j)

Next

'I don't think this nesting is right. I want to have arrTotal contain
'both arrOne and arrTwo:
For i = 0 To UBound(arrTwo, 1)

arrTotal(i) = arrTwo(i, j)

Next

Next

End Sub

Sorry if I wasn't clear enough. I'd appreciate any thoughts. Thanks!
Sep 7 '07 #1
4 1396
Not sure what you want.
Ary1
1
2
3
Ary2
7
8
9

Now:
Ary3(5)?
1
2
3
7
8
9

-or-

Ary3(2,1)?
1 - 7
2 - 8
3 - 9
Sep 7 '07 #2
Thanks for your reply. I think I want it to display like this:

Ary3(2,1)
1 - 7
2 - 8
3 - 9
Sep 7 '07 #3
Tig201
103 100+
Why would you need two loops Just try:
Expand|Select|Wrap|Line Numbers
  1. For i = 0 to UBound(arrTwo, 1)
  2.   arrTotal(i,0) = arrOne(i)
  3.   arrTotal(i,1) = arrTwo(i)
  4. Next
  5.  
Sep 7 '07 #4
Try this then:

Expand|Select|Wrap|Line Numbers
  1.  Public Class Form1
  2.     Dim ary1() As Integer = {1, 2, 3, 4}
  3.     Dim ary2() As Integer = {7, 8, 9}
  4.     Dim ary3(,) As Integer
  5.  
  6.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7.         Dim x As Integer
  8.         Dim arySize As Integer = UBound(ary1)
  9.         If UBound(ary2) > arySize Then arySize = UBound(ary2)
  10.         ReDim ary3(arySize, 1)
  11.         For x = 0 To UBound(ary1)
  12.             ary3(x, 0) = ary1(x)
  13.         Next
  14.         For x = 0 To UBound(ary2)
  15.             ary3(x, 1) = ary2(x)
  16.         Next
  17.     End Sub
  18. End Class 
Sep 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alex Hopson | last post by:
Hi, I'm trying to modify a shopping cart script from Mastering PHP/MySQL and am having trouble setting up some arrays for it. The original code, below, stores the cart items in a session...
2
by: paul | last post by:
Hi all, I have a 2D array, which I am trying to access, but I am having problems doing this: If, for instance, I use a nested for loop to go through the values, using something like echo...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
2
by: Nathan Sokalski | last post by:
I have a multidimensional array declared as the following: Dim guesses(14, 5) As Integer I want to assign all values in a specific dimension to another array declared as follows:
5
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.