473,586 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merging Two 1D Arrays into One

5 New Member
Good Afternoon All, I am working with Visual Studio.Net 2003

If I have Two 1D Arrays:

Dim intX() As Integer = {1, 3, 5, 7, 9, 11, 13, 15, 17}
Dim intY() As Integer = {2, 4, 6, 8, 9, 10, 12, 14, 16}
Dim intZ(17) As Long

and need to merge array intX with array intY to form a new array intZ, is this possible?????

Any Help would be appreciated, Thanx In Adavance!

SSG A
Go Army
May 12 '07 #1
5 1839
Killer42
8,435 Recognized Expert Expert
If I have Two 1D Arrays:

Dim intX() As Integer = {1, 3, 5, 7, 9, 11, 13, 15, 17}
Dim intY() As Integer = {2, 4, 6, 8, 9, 10, 12, 14, 16}
Dim intZ(17) As Long
and need to merge array intX with array intY to form a new array intZ, is this possible?????
The simplest way would be two For loops, something like...
Expand|Select|Wrap|Line Numbers
  1. Dim I As Long
  2. For I = 0 To 8
  3.   intZ(I) = intX(I)
  4. Next
  5. For I = 0 To 8
  6.   intZ(I+9) = intY(I)
  7. Next
Of course, you could just do both the assignments within the one loop if you prefer.

If you need the new list sorted, it's probably simplest to just sort inZ() after joining them.
May 13 '07 #2
Sarge
5 New Member
The simplest way would be two For loops, something like...
Expand|Select|Wrap|Line Numbers
  1. Dim I As Long
  2. For I = 0 To 8
  3.   intZ(I) = intX(I)
  4. Next
  5. For I = 0 To 8
  6.   intZ(I+9) = intY(I)
  7. Next
Of course, you could just do both the assignments within the one loop if you prefer.

If you need the new list sorted, it's probably simplest to just sort inZ() after joining them.
Thanx for the reply Killer42, I tried the code and I get an error of outside bound os the array, here is the whole thing I am trying to do:

Dim intX() As String = {4, 9, 12, 15, 22, 33, 44, 66, 72, 84, 87, 92, 96, 98, 99}
Dim intY() As String = {6, 8, 12, 16, 24, 31, 68, 71, 73, 74, 81, 93, 94}
Dim intZ(27) As String

I am wanting to merge the two arrays intX and intY into intZ and place the output to a messagebox that has the two merge arrays as so:

4, 6, 8, 9, 12, 12, 15, 16, 22, 24, 31, 33, 44, 66............. ......etc.

so intX has 15 elements, intY has 13 elements and after they merge into intZ, intZ will have 28 elements.

Any Help Killer42 would be appreciated, thanx
May 13 '07 #3
Killer42
8,435 Recognized Expert Expert
Thanx for the reply Killer42, I tried the code and I get an error of outside bound os the array...
The technique I demonstrated is very simple and will certainly work, so I'd guess there must have been some sort of bug in the implementation. At a guess, perhaps you tried to copy my code too precisely. I note that in the latest example your input arrays are different sizes, while my code assumed they were the same size.

In any case, show us the actual code you used, and let's see if we can beat the problem.

P.S. Personally, I never allow my arrays to start at (0). It causes too much confusion, because humans just don't think that way. I don't know what the equivalent would be in VB.Net, but in VB6 I always define them in the form intX(1 To 15) to ensure that I know exactly what I'm getting.
May 13 '07 #4
Sarge
5 New Member
Killer42, thanx for the response:

Here is what I am wanting to do merge intX and intY into intZ and show the result in a messagebox:


Dim intX() As String = {4, 9, 12, 15, 22, 33, 44, 66, 72, 84, 87, 92, 96, 98, 99}
Dim intY() As String = {6, 8, 12, 16, 24, 31, 68, 71, 73, 74, 81, 93, 94}
Dim intZ(27) As String

I am wanting to merge the two arrays intX and intY into intZ and place the output to a messagebox that has the two merge arrays as so:

4, 6, 8, 9, 12, 12, 15, 16, 22, 24, 31, 33, 44, 66............. ......etc.

I know in the project I have included a TextBox for output just to see it work but I will figure that out as soon as I can get this to work

Expand|Select|Wrap|Line Numbers
  1. Dim intX() As Integer = {"4", "9", "12", "15", "22", "33", "44", "66", "72", "84", "87", "92", "96", "98", "99"}
  2.     Dim intY() As String = {"6", "8", "12", "16", "24", "31", "68", "71", "73", "74", "81", "93", "94"}
  3.     Dim intZ(26) As String
  4.  
  5.  
  6.  
  7.  
  8.     Private Sub btnMerge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMerge.Click
  9.  
  10.  
  11.         Dim I As Long
  12.  
  13.  
  14.  
  15.         For I = 0 To 14
  16.             intZ(I) = intX(I)
  17.  
  18.         Next
  19.  
  20.         For I = 0 To 12
  21.             intZ(I + 12) = intY(I)
  22.             txtBox1.Text = txtBox1.Text & intZ(I)
  23.  
  24.  
  25.        Next 
when I merge the arrays not all of it shows in the message box, I was trying to find an attachment feature to upload the zipped file to you, I guess they dont allow that.

Thanx for the help
Sarge
May 14 '07 #5
Killer42
8,435 Recognized Expert Expert
Your code only moves the first 13 occurrences of the array into the textbox

I believe your first loop is OK. The second loop looks as though it has two problems.
  1. intZ(I + 12) = intY(I)
    Where did the +12 come from? Shouldn't this be +13 or +14? (I hate zero-based arrays.)
  2. txtBox1.Text = txtBox1.Text & intZ(I)
    This looks OK, but as I said, it's only being applied to the first 13 elements
May 15 '07 #6

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

Similar topics

1
6021
by: Tmenke | last post by:
Can someone help, I have two arrays and want to merge them into a third array.What I want to do is, after I create this third array (combination of the first two) is to erase the original two arrays from memory.Is there a command in VB5 that will do this ? Thanks, Tom M
4
6798
by: Bush will disarm all workers next | last post by:
I'm new to JavaScript. So please excuse my mistakes. I need help on merging two arrays into a third one. There is an array a = {188, 180, 159, 67 } There is another array b={'Rio de Janeiro', 'Sao Paulo', 'Brasilia', 'Belo Horizonte'} How can I merge them to produce an array that is equivalent to this: bg.xValues = ; bg.xValues = ;...
3
1880
by: Patrick | last post by:
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best, easiest, most efficient way of merging the 2 XML Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any pre-requisites? Any other...
3
1774
by: André Hänsel | last post by:
Hi! Is there a better way to do this? $command = '$array = array_merge($array,$array);'; eval($command); Regards, André
8
3672
by: vidishasharma | last post by:
Can somebody suggest good URL which contains code for merging of 2 or more priority queues in c#.
11
4165
by: holla | last post by:
Write the following functions that can be called by a C program: Write a function to populate an array with random integers between 0 and 99. Use the following functions of which the prototypes are to be found in stdlib.h • randomize() – use once to initialize the randomization process • rand() – generates a random number between 0 and the...
5
10908
by: John | last post by:
Hi Is there a way to merge two or more single dimension string arrays into a single, single dimension string array? Thanks Regards
1
3095
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 a,b,c into another array f.. I can do two arrays, but I have issues when trying to do all three and when I do the even/odd compare I only get 2 numbers...
1
1649
by: kliopatraisis | last post by:
I think I've been working on this assignment for too long and my brain has stopped making connections! Basically, we are making a very simple version of AutoCAD, called HomeCAD. The problem I am having is this: Each House object contains an ArrayList of Storeys. Each Storey within the ArrayList contains a HashMap of Rooms. We are required to...
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6610
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.