I want to implement a Delete duplicate Rows in a ListBox.
I am unsure of what to do.
Heres the pseudo code I have in mind:
Do a global scan in a main loop
a. Store one Row Contents in RowSource --> LB.Cell(LoopIdx,-1)
That loop uses DownTo 0
b. Add an inside loop (sub loop) to scan the whole ListBox
Compare RowSource contents to LB.Cell(LoopIdx - 1,-1)
If I found a duplicate, delete it
and remove 1 to LoopIdx
What is your feeling ?
<some minutes ellapsed and >
Heres the code I actually wrote:
[code] Dim RowCnt As Integer // Number of Rows in the ListBox
Dim LoopIdx As Integer // Main Loop Indice
Dim DbleIdx As Integer // Sub Loop Indice
Dim RawSource As String // Row contents to compare to the rest of the ListBox contents
// Get the number of rows in the ListBox
RowCnt = LB_Bookmarks.ListCount // 1-based value
// Loop thru the ListBox contents
For LoopIdx = RowCnt DownTo 1
// Get One Row Contents (to compare to the other Rows)
RawSource = LB.Cell(LoopIdx - 1,-1)
// Scan the ListBox for a duplicate
For DbleIdx = 1 to LoopIdx - 1
If RawSource = LB.Cell(DbleIdx,-1) Then
// I found a duplicate, so delete it
LB.RemoveRow LoopIdx - 1
// Remove 1 to LoopIdx
LoopIdx = LoopIdx - 1 // What can be the impact on the main loop ?
End If
Next
// To avoid 1, Infinite Loop
If UserCancelled Then Exit
Next[/code]
The code above seems to work. Not placed in the correct project, but it works.
BTW: after a simple check, it seems that TWO instances of the same data stays on the end of the process: two Rows with the same contents and I do not make a real compare between the original contents and the resulting contents. I only checked the results.
Worst, I forgot that the file I used as source to delete duplicates is a bit bad: Column 2 data does not always correspond to Column 1 data on a Row basis. *
So, I have something wrong, but how do I correct that ?
- That source file was created at an early stage of the project when I had bad storage for unknown reasons (Column 1 have an URL, and Column 2 have that url Title). Sometimes I had URL with another Title (a previous one it seems).