How can I filter duplicates in VB6? In a list.
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 :)
Sort + scan.
It's even better to always answer with <= the length of the question ;)
Quote from: Adron on March 19, 2004, 11:06 AM
Sort + scan.
It's even better to always answer with <= the length of the question ;)
ok, let me try again:
"Insertion Sort & Elimination"
Actually, qsort + scan might be faster if there are only a few duplicates...
Quote from: Adron on March 19, 2004, 11:35 AM
Actually, qsort + scan might be faster if there are only a few duplicates...
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.
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
Thank you Grok once again...Simple Question doesn't always deserve a simple answer...