Jump to content
Melba23

ArrayMultiColSort -New Release 15 Sep 15

Recommended Posts

BrewManNH

Not really sure what column 2 is supposed to be sorting by. The explanation is a bit vague and the sort doesn't seem to fit what I think it's saying.

 

BTW, wouldn't this be faster using an SQLite DB in memory?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

BrewManNH,

Sorry if the explanation was lacking. If you use a string, elements in that column will be sorted in the order set in the string. Im this case if you were to use just "ascending/descending" for column 2 then the strings would be ordered "P,Q,R,S / S,R,Q,P" - by using the string they are in fact ordered "S,Q,P,R". The idea is that if you use known strings as elements (e.g. "Male,Female,Unknown") you can order them as you wish and not necessarily in alpha/reverse alpha order. Clearer now? :)

And it could well be quicker using SQLite. But I wanted to do it in AutoIt and I will leave the other solution to jchd. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
c.haslam

IMHO This is worthy of being included in Array.au3.

I have found one small error: if I code:

Local $sortSpecsAr[][] = [[$kNatGp,0],[$kIncl,0],[$kExcl,0],[$kUdf,0]]  ; all ascending
    if _ArrayMultiColSort($resultsAr,$sortSpecsAr)='' Then
        MsgBox(0,' _ArrayMultiColSort','@error = '&@error)
    EndIf

I see @error=0


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
Melba23

c.haslam,

If all goes well then @error should indeed be 0, but I have no way of telling if that is the case - what value for @‌error were you expecting?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
c.haslam

Sorry for an incomplete post.

I was expecting success. You wrote:

; Return values .: Success: The sorted array
;                  Failure: An empty string with @error set as follows
;                            @error = 1 with @extended set as follows (all refer to $sIn_Date):
;                                1 = Array to be sorted not 2D
;                                2 = Sort data array not 2D
;                                3 = More data rows in $aSortData than columns in $aArray
;                                4 = Start beyond end of array
;                                5 = Start beyond End
;                            @error = 2 with @extended set as follows:
;                                1 = Invalid string parameter in $aSortData
;                                2 = Invalid sort direction parameter in $aSortData

So I expected the sorted array to be returned.


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
jchd

The array is to be passed ByRef so it doesn't need to be "returned", strictly speaking.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
c.haslam

True. But the documentation and code should match.


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
jchd

Trust the code: contrary to the dox, it's a poor liar.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Melba23

c.haslam.

As I stated above, if the @error returned is 0 then the function ran successfully - what you should do is test for that rather then the return value. I will look at perhaps changing the code and documentation a bit so that they match, but do remember that a foolish consistency is the hobgoblin of little minds.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

[New Release] - 15 Sep 15

Changed: UDF can now sort columns in any order.

New files and zip in first post.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
c.haslam

Thank you for the update


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
Bizzaro

I'm wondering if this UDF can help me.

 

I have a 2D array and I'm ordering the items by one of the columns, lowest to high number. However some of the numbers are the same. I would like to then sort the rows by another column, so if several of the entries into the array rows in the column I'm sorting are "2", I'd then like to sort these rows by another column.

Is this what your UDF does? Or is there is a very simple solution that I can use to action my requirements?

Share this post


Link to post
Share on other sites
Melba23

Bizzaro,

Is this what your UDF does?

Try it and see - you should find that it does exactly what you want.

M23 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mLipok

Just for note - added here:
https://www.autoitscript.com/wiki/User_Defined_Functions#Misc

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
Melba23

Bizzaro.

Her is a short example doing what you require:

#include <Array.au3>
#include <ArrayMultiColSort.au3>

Global $aOrg[20][2]

For $i = 0 To 19
    $aOrg[$i][0] = Random(1, 9, 1)
    $aOrg[$i][1] = Random(1, 9, 1)
Next

_ArrayDisplay($aOrg, "Original", Default, 8)

Global $aSortData[][] = [[0, 0], [1, 0]]

_ArrayMultiColSort($aOrg, $aSortData)

_ArrayDisplay($aOrg, "Multi Sorted", 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._______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

 

Share this post


Link to post
Share on other sites
Bizzaro

Melba, thank you for your help. Your UDF is fantastic for my needs and i'll be using it a lot. It should be included automatically IMO as it is invaluable.

 

Share this post


Link to post
Share on other sites
Trolleule

Nice work, helped me right now. Stay on ! :)

Share this post


Link to post
Share on other sites
Funtime60
Posted (edited)

I love this, but I've hit a snag in my latest usage of it.

In ascending sorting I have 9 being set above 10,11,12,etc...

I think I understand the issue as I have seen it in other things.

I was wondering if there were any solution?

Thank you for your time.

 

EDIT:

I have realized that I can correct the problem externally in NP++, however this isn't viable for the full sized files as they are thousands of entries long so I'd have to add 0's to the front of every number in the sorting columns with fewer digits than the larger number. It would be nice if this could be done internally with the results matching the original format.

I have no idea how hard this would be as I have no idea how to do it on my own in an infinite manner let alone integrate it into a function I don't understand.

Again, thank you for your time.

 

Edit 2:

I have tested and have found the issue I think. Please forgive my poor terminology, but I think this sorts like you would alphabetize words. Compare the first digits ignoring any digits after that. A 9 is greater than 10 because It only seems to look at 9 and 1 and 9 is greater than 1 so the 0 in 10 is ignored. To solve this you can pad the sorting columns with preceding zeros 09 will be less than 10 because 0 is less than 1. As such I have write a poorly designed  thing to automatically pad a column, though I am still making it procedural so any columns can be padded and the padding maybe left behind in the output. I can't say for sure on this last point as I have yet to complete a test of a final project.

On another note while I did write my bit to compensate for negatives, turning -9 into -09 and not 0-9, the original UDF does not seem to support negative numbers properly as far as I can tell.

All of this is based purely off of my minimal observations and testing with extremely limited understanding of the original UDF's inner workings. I would like apologize for any mistakes I have made in the process.

Thank you for taking the time to read this.

Edited by Funtime60
I had more Ideas

Share this post


Link to post
Share on other sites
Funtime60
Posted (edited)
#include <ArrayMultiColSort.au3>

#Region Init
;Source data to be sorted, any 2D array.
Local $testfilearray1[3][3] = [["123", "321", "-1"], ["123", "-31", "13"], ["123", "-321", "-12"]]
;Must come anywhere after line above, but before loops below.
Local $testsize = UBound($testfilearray1) - 1
;Must predetermine the sorting format.
Global $aSortData[][] = [[1, 0], [2, 0]]
#EndRegion Init


#Region Add Pad
;Sorry, I'd explain, but even after only a few hours, I've already forgotten whay most of this does.
Local $col1max = _ArrayMax($testfilearray1, 1, -1, -1, 1)
Local $col2max = _ArrayMax($testfilearray1, 1, -1, -1, 2)
Local $col1maxdig = StringLen($col1max)
Local $col2maxdig = StringLen($col2max)
Local $sorttotalcount = UBound($aSortData) - 1
For $sortcount = 0 To $sorttotalcount Step 1
    Local $colnum = $aSortData[$sortcount][0]
    For $testfilerownum2 = 0 To $testsize Step 1
        Local $neg1 = StringSplit($testfilearray1[$testfilerownum2][$colnum], "")
        If $neg1[1] = "-" Then
            Local $neg1testfile = StringSplit($testfilearray1[$testfilerownum2][$colnum], "-")
            Local $testcol1dig = StringLen($neg1testfile[2])
        Else
            Local $testcol1dig = StringLen($testfilearray1[$testfilerownum2][$colnum])
        EndIf
        While $testcol1dig < $col1maxdig
            Local $neg1 = StringSplit($testfilearray1[$testfilerownum2][$colnum], "")
            If $neg1[1] = "-" Then
                Local $neg1testfile = StringSplit($testfilearray1[$testfilerownum2][$colnum], "-")
                $testfilearray1[$testfilerownum2][$colnum] = "-0" & $neg1testfile[2]
                Local $testcol1dig = StringLen($neg1testfile[2])
            Else
                $testfilearray1[$testfilerownum2][$colnum] = "0" & $testfilearray1[$testfilerownum2][$colnum]
                Local $testcol1dig = StringLen($testfilearray1[$testfilerownum2][$colnum])
            EndIf
            Local $neg1 = StringSplit($testfilearray1[$testfilerownum2][$colnum], "")
            If $neg1[1] = "-" Then
                Local $neg1testfile = StringSplit($testfilearray1[$testfilerownum2][$colnum], "-")
                Local $testcol1dig = StringLen($neg1testfile[2])
            Else
                Local $testcol1dig = StringLen($testfilearray1[$testfilerownum2][$colnum])
            EndIf
        WEnd
    Next
Next
_ArrayDisplay($testfilearray1, "$testfilearray1")
#EndRegion Add Pad

;Now take the array and plug it into _ArrayMultiColSort($testfilearray1, $aSortData)

This is my procedural padding thing, it's technically not a UDF.

If this shouldn't be here, just ask. I'll try to remove it in a reasonable amount of time.

Thanks for your time.

 

EDIT:

On a side note, why does the syntax highlighter not work on my post?

 

EDIT 2:

Please read the next page.

Edited by Funtime60
Apologizing for my noobyness at posting code.

Share this post


Link to post
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

×