Results 1 to 11 of 11

Thread: [RESOLVED] Eliminate Duplicates In Array

Threaded View

  1. #1

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Resolved [RESOLVED] Eliminate Duplicates In Array

    I'm trying to eliminate duplicates from one array, and store them into another, but this code doesn't seem to do it right. Can anyone give me a hand on fixing it. Thanks in advance.

    [EDIT] Fixed subscript out of range error.

    VB Code:
    1. Option Explicit
    2.  
    3. Dim A(9) As Long
    4. Dim B() As Long
    5. Dim I As Long, J As Long, K As Long
    6.  
    7. Private Sub Form_Activate()
    8.  
    9.     A(0) = 0
    10.     A(1) = 1
    11.     A(2) = 2
    12.     A(3) = 3
    13.     A(4) = 4
    14.     A(5) = 5
    15.     A(6) = 6
    16.     A(7) = 7
    17.     A(8) = 8
    18.     A(9) = 9
    19.    
    20.     ReDim B(0) As Long
    21.  
    22.     For I = 0 To UBound(A)
    23.         For J = 0 To UBound(B)
    24.             If A(I) <> B(J) Then
    25.                 If J = UBound(B) Then
    26.                     B(J) = A(I)
    27.                     K = K + 1
    28.                     ReDim Preserve B(K) As Long
    29.                 End If
    30.             ElseIf A(I) = B(J) Then
    31.                 Exit For
    32.             End If
    33.         Next J
    34.     Next I
    35.    
    36.     For I = 0 To UBound(B)
    37.         Print B(I)
    38.     Next I
    39.  
    40. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width