Jacobus Duvenhage
Jacobus Duvenhage

Reputation: 1

I need to compare 2 arrays with the same values in vb.net

I do have 1 large array +-11000000 elements. What I need to do is to remove the duplicates in this array. What I do is to duplicate the 1st array to a 2nd array. I then start with array 1 element 0 and compare that element to each element in the 2nd array with a loop. If it finds a duplicate it writes a empty string to the 2nd array at the element where the duplicate is. This is getting me confused because when I run through array 2 and I pick up a duplicate then I count it as 1 on checking the next element it finds a duplicate(note this duplicate is not the same as 1st duplicate) the count goes to 2 and it deletes that element that is wrong. I end up with an empty array. See code:

 Dim X As Long = 0
        Dim Y As Long = 0
        Dim Z As Long = 0
        Dim A As Integer = 0
        Dim FileNo As Integer = 1
        Me.Hide()
        Me.Visible = False
        NotifyIcon1.Visible = True

        For X = 0 To UBound(arrToCheck)
        Btn2.Text = " Busy with Line  " & X
        NotifyIcon1.Text = Btn2.Text
        My.Application.DoEvents()
        For Y = 0 To UBound(arrToCompare)
            Btn5.Text = "arrTocompare " & Y
            My.Application.DoEvents()
            If Trim(arrToCheck(X)) = Trim(arrToCompare(Y)) Then
                A = A + 1
                If A >= 2 Then
                    arrToCompare(Y) = ""
                    My.Application.DoEvents()
                End If
               A = 0
                ' A = A + 1
            End If


            My.Application.DoEvents()
         Next


            My.Application.DoEvents()
        Next

Array small example

AMERIKAANSE AMERIKAANSE massa

Result must be AMERIKAANSE massaenter code here

Upvotes: 0

Views: 732

Answers (1)

Denver Coder
Denver Coder

Reputation: 77

If this is all of your code I don't see where you are setting the value of the array if it doesn't find a match. So for example you have two arrays [1, 2, 3] and [1, 2, 3]. It checks the first element in the first array and compares it to the first element in the second array, (1 = 1). So it says, "Match". Then it sets "A" to 1. Then it checks the first element of the first array against the second element of the second array, (1 != 2). So it says, "No Match". At this point you should write the second element of the second array to your new array. Hope that kinda makes sense.

Upvotes: 1

Related Questions