title: Comparing two string array and returning the differences of each in vb6 with a good performance
body: <p>I got 2 expandable arrays with strings in them and I want to compare both with each other to see which includes strings that the other dont.</p>
  
  <p>lets say my arrays are like: </p>
  
  <pre><code>ARRAY - 1       ARRAY - 2
     a1               a1
     a2               a2
     a3               a3
     a9               a4
     a10              a8
     a11              a10
     a12              a11
  </code></pre>
  
  <p>i wanna get the result as: </p>
  
  <pre><code>ARRAY - 4       ARRAY - 5       ARRAY - 6
     a9               a4             a1
     a12              a8             a2
                                     a3
                                     a10
                                     a11
  </code></pre>
  
  <p>another 3 different array should give me the difference of array1 when compared to array 2</p>
  
  <pre><code>-array4 here gives the strings that is included in array1 but not found in array2
  -array5 here gives the strings that is included in array2 but not found in array1
  -array6 here gives the strings that is found in both
  </code></pre>
  
  <p>for this i ve coded:</p>
  
  <pre><code>i = 0
  j = 0
  
  For Each innerElement1 In CompareElement1 'CompareElement1 is the array1 here
  
      NoneFound = 1
  
      'Ones thats in first element also found in second element..
      For Each innerElement2 In CompareElement2 'CompareElement2 is the array2 here
  
          If innerElement1 = innerElement2 Then
  
              'Expand array
              ReDim Preserve IncludedInBoth(0 To UBound(IncludedInBoth) + 1)
              IncludedInBoth(i) = innerElement1
              'Item found in both so NoneFound is 0.
              NoneFound = 0
              i = i + 1
  
          End If
  
      Next
  
      'Ones thats in first element but not found in second element..
      If NoneFound = 1 Then
  
          'Expand array
          ReDim Preserve NotIncludedInElem2(0 To UBound(NotIncludedInElem2) + 1)
          NotIncludedInElem2(j) = innerElement1
          j = j + 1
  
      End If
  
  Next
  
  'Seperate Comparison for the ones that found in second element _
   but not found in first element..
  i = 0
  
  For Each innerElement1 In CompareElement2
  
      NoneFound = 1
  
      'Ones thats in second element also found in first element.
      For Each innerElement2 In IncludedInBoth
  
          If innerElement1 = innerElement2 Then
  
              'Item found in both so NoneFound is 0.
              NoneFound = 0
  
          End If
  
      Next
  
      'Ones thats in second element but not found in first element..
      If NoneFound = 1 Then
  
          'Expand array
          ReDim Preserve NotIncludedInElem1(0 To UBound(NotIncludedInElem1) + 1)
          NotIncludedInElem1(i) = innerElement1
          i = i + 1
  
      End If
  
  Next
  </code></pre>
  
  <p>my code up there exactly does the comparing and giving the true answer but with a lack of performance caused by inner <code>for each</code> calls is there a way to do this comparing with a faster way? its taking like forever to finish this comparing.. </p>
  
  <p>also a little note:</p>
  
  <pre><code>array1 and array2 are two different sized arrays that contains thousands(~100.000)of strings in each.
  also they are not in order. i would like to learn how to order them alphabetically.
  </code></pre>