Merging Two 1D Arrays into One

Sarge

New member
Joined
May 11, 2007
Messages
3
Programming Experience
Beginner
:confused: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
 
Thnx cjard, that looks as if it will work, now Im trying to display the results to a messagBox, any Ideas????


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


Array.Copy(intX, intZ, 0)
Array.Copy(intY, intZ, 0)

messageBox.show ("Results", & ???????)

??????? being where I am stuck it wont accept intZ, I get an error saying a 1 dimesional array cannot be converted to string

Again Thanx
 
Thnx cjard, that looks as if it will work, now Im trying to display the results to a messagBox, any Ideas????

??????? being where I am stuck it wont accept intZ, I get an error saying a 1 dimesional array cannot be converted to string




I dont understand.. I dont even really understand how to answer your question; to me it is quite obvious why a list of numbers is very different to a string. A MessageBox requires a string, not an array of numbers. Perhaps if you said what you wanted your messagebox to look like then I would be able to understand the request?

If youre using this just to check that it has been done properly, youre better off using the debugger. Just type ?intZ in the Immediate window when the program is on a breakpoint
 
My Apologies Cjard You are Very Correct

I apologize for the confusion I have caused, The output in fact needs to be in a text box, I was able to get part of it working with the following code:
VB.NET:
Dim intX() As Integer = {4, 9, 12, 15, 22, 33, 44, 66, 72, 84, 87, 92, 96, 98, 99}
    Dim intY() As Integer = {6, 8, 12, 16, 24, 31, 68, 71, 73, 74, 81, 93, 94}
    Dim intZ(27) As Integer






    Private Sub btnMerge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMerge.Click

        Dim I As Integer

        For I = 0 To 14

            intZ(I) = intX(I)

        Next

        For I = 0 To 12

            intZ(I + 12) = intY(I)
            txtBox1.Text = txtBox1.Text & intZ(I) & intZ(I + 12)

        Next

    End Sub

The out put in the textbox is supposed to be:

4, 6, 8, 9, 12, 12, 15, 16, 22, 24, 31, 33, 44, 66, 68, 71, 72, 73, 74, 81, 84, 87, 92, 93, 94, 96, 98, 99

With the code listed above this is what the out put is:

4, 6, 9, 8, 12, 12, 15, 16, 22, 24, 33, 31, 44, 68, 66, 71, 72, 73, 84, 74, 87, 81, 92, 93, 6, 94

As you can see there is a small problem, I would appreciate another set of eyes on it to help me see the mistake, ALSO!!!!! I know that it would be easier to use copy.array and sort it but, I cannot use any Array Methods with this. I will also upload the .zip with the project in it if you want to see how it acts.

Any Help Would Be Appreciated, Again Sorry for the confusion.

Sarge
 

Attachments

  • Merging Arrays.zip
    25.8 KB · Views: 15
Try working these in somewhere:

For i as Integer = 0 to firstArray.Length - 1

For i as Integer = firstArray.Length to secondArray.Length


That way youre not coding with fixed numbers... :)
 
Back
Top