'************************************** 'Windows API/Global Declarations for :A ' Better, Faster,Remove Duplicates Functio ' n (Kill Dupes, Remove Dupes, Kill Duplic ' ates) '************************************** None. '************************************** ' Name: A Better, Faster,Remove Duplicat ' es Function (Kill Dupes, Remove Dupes, K ' ill Duplicates) ' Description:Please check "http://chad. ' offroadextremes.com/forums" for all my s ' ource code and projects. This is a very ' fast, very efficient RemoveDupes Functio ' n. Every single RemoveDupes Sub/Function ' I have ever seen on PSCode has been very ' slow and never removes all the duplicate ' list items. If the List/Combo contained ' more than one duplicate, only the first ' duplicate was removed. My Function, howe ' ver, removes every single duplicate no m ' atter how many there are. It also does i ' t very quickly without going back throug ' h the list. It only sweeps through the l ' ist once. This is the fastest and most e ' fficient way of removing dupes in VB. Al ' so, I have added the options to remove a ' ll matches no matter the Case or if it h ' as spaces or not, remove matches that on ' ly match exactly or any combination of m ' atching options. As an added bonus, I wr ' ote it as a Function to return the numbe ' r of duplicates removed. You can call th ' is Function like you would a sub for sim ' plicity, or use anything to display the ' number of dupes removed. EXAMPLES: [1] C ' all RemoveDupes(List1, True, True) [2] C ' all MsgBox(RemoveDupes(List1, True, True ' )) [3] lngDupes& = Call RemoveDupes( ' List1, True, True) ' By: Chad Roe (from psc cd) ' ' ' Inputs:lstList = The List you are remo ' ving dupes from. blnLowerCase = Wether y ' ou want to match LCase or not. blnNoSpac ' es = Wether you want to match with or wi ' thout spaces. Setting both to True will ' remove all duplicates that are the same ' no matter what Case they are or if they ' contain spaces or not. EXAMPLE: "aA a" i ' s the same as "aaa" if both are set to T ' rue. "aA a" and "aaa" are different if b ' oth are set to False. ' ' Returns:Returns a ListBox or ComboBox ' with no duplicate items. ' 'Assumes:As you can see in the code, aft ' er an item is removed, I set the current ' Check Item back one to make up for the i ' tem just removed. This is why this Funct ' ion removes ALL duplicate items and not ' just the first one. Also, I do not use D ' oEvents because this drastically slows d ' own the process. To me, this is the grea ' test Dupe Killer that can be written in ' Visual Basic. ' 'Side Effects:None. '************************************** Public Function RemoveDupes(lstList As Control, blnLowerCase As Boolean, blnNoSpaces As Boolean) As Long Dim strItem As String, strCheck As String Dim intItem As Integer, intCheck As Integer RemoveDupes& = lstList.ListCount For intItem% = 0 To lstList.ListCount - 1 For intCheck% = intItem% + 1 To lstList.ListCount - 1 strItem$ = lstList.List(intItem%) If blnLowerCase = True Then strItem$ = LCase(strItem$) If blnNoSpaces = True Then strItem$ = Replace(strItem$, " ", "") strCheck$ = lstList.List(intCheck%) If blnLowerCase = True Then strCheck$ = LCase(strCheck$) If blnNoSpaces = True Then strCheck$ = Replace(strCheck$, " ", "") If strItem$ = strCheck$ Then Call lstList.RemoveItem(intCheck%) intCheck% = intCheck% - 1 End If Next intCheck% Next intItem% RemoveDupes& = RemoveDupes& - lstList.Li ' stCount End Function