Link to home
Start Free TrialLog in
Avatar of mari_carmen
mari_carmen

asked on

Removing duplicate data from an array

The code below displays job numbers.

        CompleteJobs.JobNum2(K).Text = TempJobs2(M)
            K = K + 1
            M = M + 1
        Loop Until TempJobs2(M) = Empty

The problem is duplicate numbers are displayed. How can i remove the duplicate job numbers when displaying.
Avatar of Mirkwood
Mirkwood

From the EE FAQ:

"It is up to you to assign points to the question based on its difficulty. As a guide, a basic question is worth 50 points, an intermediate question 100 points, and an advanced question 200 points. The more points assigned to a question, the more likely it will be answered."

ASKER CERTIFIED SOLUTION
Avatar of waty
waty
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
c'mon boys.... mari_carmen is only with us since 13 June. I've heard that some new people did not get the customary 200 points to start with. If mari_carmen is one of those unfortunates, it would add up to (16 days) 80 points or thereabouts. No wonder mari_carmen has only got 25 points to spare...

mari_carmen, did you get your 200 points when you started (don't lie because Mirkwood has ways and means of checking... :o)


What I'd do with an array to remove dupes is this:

Dim aCol as New Collection

On Error Resume Next

Dim i As Long
For i = LBound(TempJobs2) to UBound(TempJobs2)
    aCol.Add TempJobs2(i), "k" & i
Next i

For i = 1 To aCol.Count
    CompleteJobs.JobNum2(i).Text = aCol(i)
Next i

Set aCol = Nothing

It seems a bit simpler than waty's solution to me. Admittedly, it does use more memory than waty's suggestion, but it seems to me that the simplest way is often the best.

And I can't remember if Collections are 1 based or 0 based. If they are 0 based, then the For line should read:
For i = 0 to aCol.Count - 1

And that's it.

J.
Collections are 1-based.