• Welcome to Valhalla Legends Archive.
 

Filtering Duplicates

Started by Networks, March 19, 2004, 10:03 AM

Previous topic - Next topic

Networks

How can I filter duplicates in VB6? In a list.

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 :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

#2
Sort + scan.

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

iago

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"
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

Actually, qsort + scan might be faster if there are only a few duplicates...

iago

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Grok

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


Networks

Thank you Grok once again...Simple Question doesn't always deserve a simple answer...