-
I wrote some code to remove repeated items in a list, but the only way I could get it to work is very slow and ineffective for very large lists. Please let me know how I can make this one work better. BTW the variables X and Y were dimmed already in Generals
Restart:
For X = 0 To frmMain.lstURLS.ListCount - 1
For Y = 0 To frmMain.lstURLS.ListCount - 1
DoEvents
If frmMain.lstURLS.List(X) = frmMain.lstURLS.List(Y) And X <> Y Then
frmMain.lstURLS.RemoveItem (Y)
GoTo Restart:
End If
Next Y
Next X
Thanks for taking a look.
-
Try this:
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Sub Command1_Click()
Dim iIndex As Long
Dim iCur As Long
For iCur = 1 To List1.ListCount
While iIndex > -1 And iIndex <> iCur
iIndex = SendMessage(List1.hwnd, LB_FINDSTRINGEXACT, iCur, ByVal List1.List(iCur))
If iIndex <> iCur And iIndex > -1 Then
List1.RemoveItem iIndex
End If
Wend
Next
End Sub
N.B. It would work even better and faster if you checked for repeat occurances before adding an Item to the List, then you'd only need to look for 1 Repeat Occurance.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]