Before you add the item to the listbox, send a LB_FINDSTRINGEXACT message to it to search the listbox after the string, if not found (SendMessage returns -1) then add it. The following snippet demonstrates this (I assume you know how to find SendMessage and the named constant using the API Viewer).BTW, the way you searched the ListBox is a bit stupid (sorry for being blunt), but suppose the ListBox contains three items you then start by ignoring to check if the first item matches the first item. You then compare the first item with the second item followed by comparing the first with the third. You then start over and compare the second item with the first (which is already done once already). If you wanted a nested loop as the one you have it should look like this:Code:If SendMessage(List1.hWnd, LB_FINDSTRINGEXACT, -1, ByVal sShortCut) = -1 Then List1.AddItem sShortCut End IfCode:For x = (List1.ListCount - 2) To 0 Step -1 For y = (List1.ListCount - 1) To (x + 1) Step -1 If List1.List(x) = List1.List(y) Then List1.RemoveItem y End If Next Next




Reply With Quote