array duplicate question - tricky
Hi,
I have a problem with finding the number that has the most duplicates within an array containing several thousand entries...
I can sort through and find dupes no problem, can find Min/Max and Average, but how do I go about finding the number that is duplicated the most within this array?
Small Example:
1234, 3323, 4567, 1234, 3323, 3444, 4444, 3323, 6678
I don't know what the real values will be when placed into the array, but in this example, 3323 is duplicated more times than any other number... I need to extract the number that has the most duplicates when looping through the array... Any ideas?
Does not matter how, or when extraction occurs...
Thanx a million in advance,
-Scott
Re: array duplicate question - tricky
Quote:
Originally posted by killer_cobra
Hi,
I have a problem with finding the number that has the most duplicates within an array containing several thousand entries...
I can sort through and find dupes no problem, can find Min/Max and Average, but how do I go about finding the number that is duplicated the most within this array?
Small Example:
1234, 3323, 4567, 1234, 3323, 3444, 4444, 3323, 6678
I don't know what the real values will be when placed into the array, but in this example, 3323 is duplicated more times than any other number... I need to extract the number that has the most duplicates when looping through the array... Any ideas?
Does not matter how, or when extraction occurs...
Thanx a million in advance,
-Scott
Try this ... it will give you ideas on some creative uses of string functions to solve this sort of problem. Its kinda clunky and thrown together, but should give you the idea. Definitly cuts down on lines of code if your into that :)
VB Code:
Private Sub Command1_Click()
Dim a(9) As String
Dim temp1 As Integer, temp2 As Integer
Dim i As Integer
a(1) = 1234
a(2) = 3323
a(3) = 4567
a(4) = 1234
a(5) = 3323
a(6) = 3444
a(7) = 4444
a(8) = 3323
a(9) = 6678
temp1 = 0
For i = 1 To UBound(a)
If UBound(a) - UBound(Split(Replace(Join(a, "-"), a(i) & "-", ""), "-")) > temp1 Then
temp1 = UBound(a) - UBound(Split(Replace(Join(a, "-"), a(i) & "-", ""), "-"))
temp2 = i
End If
Next i
MsgBox a(temp2) & " repeated " & temp1 & " times."
End Sub