spudw2k Posted April 9, 2015 Share Posted April 9, 2015 (edited) Here is a simple function that...I bet you can guess what it does. expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlListBox_RemoveDuplicates ; Description ...: Removes duplicate items in a Listbox control ; Syntax.........: _GUICtrlListBox_RemoveDuplicates($hWnd) ; Parameters ....: $hWnd - Handle or ControlID of the Listbox control ; Return values .: Success - 1, Listbox Cleared and Repopulated with Unique Items ; Failure - 0, sets @error to: ; |1 - $hWnd parameter is not a valid Listbox ControlID or Handle ; |2 - Listbox control has no content ; |3 - No duplicate items in Listbox control ; Author ........: Spudw2k ; Modified.......: ; Remarks .......: This function has a dependancy on Array.au3 as it utilizes _ArrayUnique ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlListBox_RemoveDuplicates($hWnd) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not $hWnd Then Return SetError(1, 0, 0) Local $iItemCount = _GUICtrlListBox_GetCount($hWnd) If $iItemCount = -1 Then Return SetError(2, 0, 0) Local $aItems[$iItemCount] For $idx = 0 To $iItemCount - 1 $aItems[$idx] = _GUICtrlListBox_GetText($hWnd, $idx) Next Local $aUniqueItems = _ArrayUnique($aItems) If UBound($aItems) <= UBound($aUniqueItems) Then Return SetError(3, 0, 0) $aItems = $aUniqueItems _GUICtrlListBox_BeginUpdate($hWnd) _GUICtrlListBox_ResetContent($hWnd) For $idx = 1 To $aItems[0] _GUICtrlListBox_AddString($hWnd, $aItems[$idx]) Next _GUICtrlListBox_EndUpdate($hWnd) Return 1 EndFunc Demo expandcollapse popup#include <GuiListBox.au3> #include <Array.au3> $GUI = GUICreate("ListBox_RemoveDuplicates", 200, 320) $hListBox = GUICtrlCreateList("", 0, 0, 198, 278) Local $aEntries[13] = ["Peanut Butter", "Jelly", "Sourdough", "Pickles", "Mustard", "Bacon", "Wheat", "Bologna", "Turkey", "Lettuce", "Onion", "Tomato", "Rye"] For $x = 0 to 10000 _GUICtrlListBox_AddString($hListBox, $aEntries[Random(0, 12, 1)]) Next $hButton = GUICtrlCreateButton("Remove Duplicates", 36, 280, 130, 20) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = -3 Then ExitLoop If $msg = $hButton Then _GUICtrlListBox_RemoveDuplicates($hListBox) WEnd ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlListBox_RemoveDuplicates ; Description ...: Removes duplicate items in a Listbox control ; Syntax.........: _GUICtrlListBox_RemoveDuplicates($hWnd) ; Parameters ....: $hWnd - Handle or ControlID of the Listbox control ; Return values .: Success - 1, Listbox Cleared and Repopulated with Unique Items ; Failure - 0, sets @error to: ; |1 - $hWnd parameter is not a valid Listbox ControlID or Handle ; |2 - Listbox control has no content ; |3 - No duplicate items in Listbox control ; Author ........: Spudw2k ; Modified.......: ; Remarks .......: This function has a dependancy on Array.au3 as it utilizes _ArrayUnique ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlListBox_RemoveDuplicates($hWnd) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not $hWnd Then Return SetError(1, 0, 0) Local $iItemCount = _GUICtrlListBox_GetCount($hWnd) If $iItemCount = -1 Then Return SetError(2, 0, 0) Local $aItems[$iItemCount] For $idx = 0 To $iItemCount - 1 $aItems[$idx] = _GUICtrlListBox_GetText($hWnd, $idx) Next Local $aUniqueItems = _ArrayUnique($aItems) If UBound($aItems) <= UBound($aUniqueItems) Then Return SetError(3, 0, 0) $aItems = $aUniqueItems _GUICtrlListBox_BeginUpdate($hWnd) _GUICtrlListBox_ResetContent($hWnd) For $idx = 1 To $aItems[0] _GUICtrlListBox_AddString($hWnd, $aItems[$idx]) Next _GUICtrlListBox_EndUpdate($hWnd) Return 1 EndFunc edit: Fixed bug - If no duplicates were found the function exited without calling _GUICtrlListBox_EndUpdate() Moved _GUICtrlListBox_BeginUpdate() after _ArrayUnique comparison. Edited April 9, 2015 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
MikahS Posted April 9, 2015 Share Posted April 9, 2015 (edited) Nice. Another idea, I'm sure you could make a function similar for ListView duplicates. Edited April 9, 2015 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
spudw2k Posted April 9, 2015 Author Share Posted April 9, 2015 I probably could, but that potentially could be a whole other beast. I'm thinking about listview column complications and how I would want to handle it. Remove rows based on duplicates within the a select column or columns. Could be a fun exercise though. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
MikahS Posted April 9, 2015 Share Posted April 9, 2015 I agree. Some standard would have to be made determining columns, rows, and the entire Listview. Could be fun, though like you said. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now