|
-
Apr 29th, 2000, 01:26 AM
#1
Thread Starter
Member
I need a less lagging Kill Duplicates
I have a list box with multiple items in the
thousands. The Kill Duplicates I made:
Code:
Dim DontKill As Long
Dim kill As Long
For DontKill = 0 To list.ListCount - 1
For kill = 0 To list.ListCount - 1
If LCase(list.list(DontKill)) Like LCase(list.list(kill)) And DontKill <> kill Then
list.RemoveItem (kill)
End If
Next kill
Next DontKill
Takes a long time to kill duplicates and then after 30
seconds or so, it'll freeze. I help on a Kill Duplicates
made for a massive numbers of items in a listbox.
[Edited by Matthew Howle on 04-29-2000 at 02:54 PM]
-
Apr 29th, 2000, 02:39 AM
#2
Addicted Member
Perhaps you are looking at it from the wrong perspective.
How are you filling the ListBox, manually or DataBound?
If you are filling it manually then you could scrutinize every attempted entry into the list. Search the list for the item, if it exists then don't add it.
If you are using DataBound list then simply fill it based on a SQL query using the DISTINCT keyword on the field.
I think using these methods would be far more efficient, I could be wrong though, it depends on what exactly you are doing.
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
Apr 29th, 2000, 02:48 AM
#3
Thread Starter
Member
I made a timer that generates the alphabet and numbers,
then adds them to a listbox. Every so often it generates
the same thing, by the time is does do that the list has
around 200-1,000 items. If I put the Kill Duplicates function in the timer, it slows the timer down by checking the listboxes for duplicates. There must be an API function that maybe searches/kills the duplicates quicker and more effiently.
I think what I'm doing is manually adding.
-
Apr 29th, 2000, 09:46 AM
#4
The LB_FINDSTRINGEXACT Message used with the SendMessage API will quickly tell you if an Item is already in the List, ie.
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()
'Clear the List and Start the Timer
List1.Clear
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
'Generate a Number Between 0 And 9
Dim sChar As String
sChar = Chr(Int(Rnd * 10) + 48)
'Only Add it to the List if it's not already there.
If SendMessage(List1.hwnd, LB_FINDSTRINGEXACT, -1, ByVal sChar) < 0 Then
List1.AddItem sChar
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|