litlmike Posted January 31, 2016 Share Posted January 31, 2016 Looking for ideas on best practices to run a "report" on data values. Specifically, I just want to take an array and produce a report that counts all of the occurrences of a string value. For example, if the array were something like this: U5L4 U5L4 U5L4 U6L5 U4L12 The reports would produce something like this: U5L4 3 U6L5 1 U4L12 1 Any help is appreciated. Thanks! _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 31, 2016 Moderators Share Posted January 31, 2016 litlmike, I would do it like this: #include <Array.au3> Global $aList[] = ["U5L4", "U5L4", "U5L4", "U6L5", "U4L12"] ; Convert list to string - use double delimiters to prevent partial matches $sList = "||" & _ArrayToString($aList, "||") & "||" ; Get unique elements of array $aUnique = _ArrayUnique($aList) ; And add a column _ArrayColInsert($aUnique, 1) ; loop through the unique elements For $i = 1 to $aUnique[0][0] ; Check how many times the element is present StringReplace($sList, "|" & $aUnique[$i][0] & "|", "") ; And store it $aUnique[$i][1] = @extended Next ; And display it _ArrayDisplay($aUnique, "", Default, 8) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
litlmike Posted January 31, 2016 Author Share Posted January 31, 2016 3 minutes ago, Melba23 said: litlmike, I would do it like this: #include <Array.au3> Global $aList[] = ["U5L4", "U5L4", "U5L4", "U6L5", "U4L12"] ; Convert list to string - use double delimiters to prevent partial matches $sList = "||" & _ArrayToString($aList, "||") & "||" ; Get unique elements of array $aUnique = _ArrayUnique($aList) ; And add a column _ArrayColInsert($aUnique, 1) ; loop through the unique elements For $i = 1 to $aUnique[0][0] ; Check how many times the element is present StringReplace($sList, "|" & $aUnique[$i][0] & "|", "") ; And store it $aUnique[$i][1] = @extended Next ; And display it _ArrayDisplay($aUnique, "", Default, 8) M23 That is very clever using the @extended, thanks! _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 31, 2016 Moderators Share Posted January 31, 2016 litlmike, A nice little trick I picked up over the years... M23 P.S. When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
iamtheky Posted January 31, 2016 Share Posted January 31, 2016 (edited) think this may be close as well, provided the list is already sorted in any fashion that groups like items #include<array.au3> Global $aList[][2] = [["U5L4"], ["U5L4"], ["U5L4"], ["U6L5"], ["U4L12"]] $k = 1 For $i = ubound($aList) - 1 to 0 step -1 If $i > 0 AND $aList[$i][0] = $aList[$i - 1][0] Then _ArrayDelete($aList , $i) $k += 1 Else $aList[$i][1] = $k $k = 1 EndIf Next _ArrayDisplay($aList) Edited January 31, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jguinch Posted January 31, 2016 Share Posted January 31, 2016 Also, look at that topic : Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
litlmike Posted January 31, 2016 Author Share Posted January 31, 2016 Thanks for the tip on reply vs quote _ArrayPermute()_ArrayUnique()Excel.au3 UDF 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