LbDupeDel




Public Declare Function SendMessageByString Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long

Public Const LB_FINDSTRINGEXACT = &H1A2

Function LBDupe(lpBox As ListBox) As Integer
Dim nCount As Integer, nPos1 As Integer, nPos2 As Integer
Dim nDelete As Integer
Dim sText As String

If lpBox.ListCount < 3 Then
LBDupe = 0
Exit Function
End If

For nCount = 0 To lpBox.ListCount - 1
Do
DoEvents2
sText = lpBox.list(nCount)
'had to update this line, sorry

nPos1 = SendMessageByString(lpBox.hwnd, _
LB_FINDSTRINGEXACT, nCount, sText)
nPos2 = SendMessageByString(lpBox.hwnd, _
LB_FINDSTRINGEXACT, nPos1 + 1, sText)
If nPos2 = -1 Or nPos2 = nPos1 Then Exit Do
lpBox.RemoveItem nPos2
nDelete = nDelete + 1
Loop
Next nCount
LBDupe = nDelete
End Function
Inputs:
the listbox to remove the duplicates from

Returns:
an integer value of the number of items removed

Assumes:
Change the decleration's of 'sendmessagebystring' and the
lb_findstring' constant to their 16-bit version to make
this 16-bit compatible. also, this function can work on
combobox's by getting the correct 'findstringexact' constant
and changing the lpBox' parameter from 'Listbox' to 'Combobox'.












( lbdupedel.html )- by Paolo Puglisi - Modifica del 17/12/2023