Important alert: (current site time 7/16/2013 1:56:03 AM EDT)
 

VB icon

_ Remove Dups From A List (NO MATTER HOW BIG THE LIST IS) _

Email
Submitted on: 2/20/2004 4:37:36 AM
By: KRYO_11  
Level: Intermediate
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 13656
(About the author)
 
     This function will remove ALL duplicate entries from a list no matter what size it is. Most duplicate removal function can only handle up to 32,767 items. Please vote and let me know what you think. Thanks
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :_ Remove Dups From A List (NO MATTER HOW BIG THE LIST IS) _
'**************************************
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 Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal sParam As String) As Long
Const LB_FINDSTRINGEXACT = &H1A2
Const LB_DELETESTRING = &H182
Const LB_GETTEXT = &H189
Const LB_GETCOUNT = &H18B
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: _ Remove Dups From A List (NO MATTER HOW BIG THE LIST IS) _
' Description:This function will remove ALL duplicate entries from a list no matter what size it is. Most duplicate removal function can only handle up to 32,767 items. Please vote and let me know what you think. Thanks
' By: KRYO_11
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=51892&lngWId=1'for details.'**************************************

Public Sub RemoveDupsFromList(ListhWnd As Long, Optional FastLag As Boolean = False)
 On Error Resume Next
 
 Dim CurCount As Long
 Dim CurPos As Long
 Dim DupEntry As Long
 Dim sItemText As String * 255
 Dim FinalOutStr As String
 CurCount = SendMessageLong(ListhWnd, LB_GETCOUNT, 0&, 0&) 'num of items In list
 If CurCount = 0 Then Exit Sub 'if no items exit
 CurPos = 0 'set start point To zero
 While CurPos < CurCount 'begin Loop
 
 sItemText = "": FinalOutStr = "" 'clear temp strings
 
 'get text of current item
 Call SendMessageStr(ListhWnd, LB_GETTEXT, CurPos, ByVal sItemText)
 FinalOutStr = RTrim(sItemText)
 If Len(FinalOutStr) > 0 Then FinalOutStr = Left(FinalOutStr, Len(FinalOutStr) - 1)
 If FinalOutStr <> "" Then 'if empty move To Next item
'checking for dups
DupEntry = SendMessageByString&(ListhWnd, LB_FINDSTRINGEXACT, 0, FinalOutStr)
If DupEntry <> CurPos Then
Call SendMessage(ListhWnd, LB_DELETESTRING, CurPos, 0) 'remove dup
CurCount = CurCount - 1
Else
CurPos = CurPos + 1
End If
 Else
CurPos = CurPos + 1
 End If
 If FastLag = False Then DoEvents 'set To True For smaller lists
 Wend
End Sub


Other 37 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
2/20/2004 4:53:19 AMKRYO_11

I have a nice sized module I have made of many more API ListBox function that I will be uploading as soon as I comment everything. I'll post that up this weekend. I will probably make an example to go with it. Some problems I had ran into with the listbox control in the past is that if you load more than 32,767 item the listbox begins acting weird with regular .ListCount, .ListIndex, etc. functions. These are ways around it.
(If this comment was disrespectful, please report it.)

 
2/21/2004 12:09:48 AMMasino Sinaga

Kryo, this is my feedback: First, I use WinXP. I Got error while calling "SendMessageLong" API function. I have been looking "SendMessageLong" in API Text Viewer but I can't find it. Second, please use an example project to implement your function. That would be better and nice. Sorry, can't give you globe at this time.
(If this comment was disrespectful, please report it.)

 
2/21/2004 12:16:02 AMMasino Sinaga

Well... (after I try several times by "trial and error"), I have found the solution for "SendMessageLong". Please change "SendMessageLong" to "SendMessageStr". And this is how to use the "RemoveDupsFromList" function (for example, I use Listbox):
Call RemoveDupsFromList(List1.hwnd, True) and it works properly. Thanks.
(If this comment was disrespectful, please report it.)

 
2/21/2004 12:22:58 AMMasino Sinaga

... 5 globes for sharing this ...
(If this comment was disrespectful, please report it.)

 
2/21/2004 4:23:01 AMKRYO_11

I apologize for that, SendMessageLong does work, however I just forgot to put it in the declarations for this example. Thanks for bringing it to my attention, I have fixed the code :)
(If this comment was disrespectful, please report it.)

 
3/17/2004 9:08:34 AMPeter Gransden

Nice work man, works good
(If this comment was disrespectful, please report it.)

 
5/23/2006 11:24:32 PMadam

good,
i have only one question, how to get string if the string display continue.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.