Valhalla Legends Forums Archive | Visual Basic Programming | Filtering Duplicates

AuthorMessageTime
Networks
How can I filter duplicates in VB6? In a list.
March 19, 2004, 4:03 PM
iago
By stepping through the list before inserting and, if it's already there, not inserting?

btw, well phrased question. 1.5 sentences. I just thought up a new strategy: when I answer questions, I'll never use more sentences than the person who asked. That way, if they want me to do work for them, they have to work as well :)
March 19, 2004, 4:11 PM
Adron
Sort + scan.

It's even better to always answer with <= the length of the question ;)
March 19, 2004, 5:06 PM
iago
[quote author=Adron link=board=31;threadid=5872;start=0#msg50419 date=1079715967]
Sort + scan.

It's even better to always answer with <= the length of the question ;)
[/quote]

ok, let me try again:

"Insertion Sort & Elimination"
March 19, 2004, 5:21 PM
Adron
Actually, qsort + scan might be faster if there are only a few duplicates...
March 19, 2004, 5:35 PM
iago
[quote author=Adron link=board=31;threadid=5872;start=0#msg50429 date=1079717726]
Actually, qsort + scan might be faster if there are only a few duplicates...
[/quote]

Well, I'm assuming that he's entering them into the list so it might be faster to do a Binary Search while inserting them and putting them in the right spot if there isn't already something there.
March 19, 2004, 5:58 PM
Grok
[code]Option Explicit

Private Const LB_FINDSTRINGEXACT = &H1A2
Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Private Sub cmdAdd_Click()
AddUnique List1, txtAdd.Text
End Sub

Private Sub AddUnique(ByVal LB As ListBox, ByVal strNewValue As String)
Dim errCode As Integer
If Len(strNewValue) = 0 Then Exit Sub 'LB_FINDSTRINGEXACT does not detect blank entries
errCode = SendMessageString(LB.hwnd, LB_FINDSTRINGEXACT, -1, strNewValue)
If errCode = -1 Then
LB.AddItem strNewValue
End If
End Sub[/code]
March 19, 2004, 6:27 PM
Networks
Thank you Grok once again...Simple Question doesn't always deserve a simple answer...
March 21, 2004, 4:11 AM

Search