Jump to content

Running a "Report"


 Share

Recommended Posts

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!

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • Moderators

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.

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...