Jump to content
Melba23

ArrayMultiColSort -New Release 15 Sep 15

Recommended Posts

To sort numeric data you need to store data in numeric format in the column. Collation as text yields "12" < "9" just because of lexicographic order used ("1" < "9"), but gives 12 > 9 since the comparison is now made in integers (also works for negative values).

The syntax shows correctly after page refresh.


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

Funtime60,

What jchd said!

So either store the elements as numbers, or if they are read in from a file as strings, you will need to loop through them using Number to convert them:

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

Global $testfilearray1[3][3] = [["123", "321", "-1"], ["123", "-31", "13"], ["123", "-321", "-12"]]

For $i = 0 To UBound($testfilearray1, 1) - 1
    For $j = 0 To UBound($testfilearray1, 2) - 1
        $testfilearray1[$i][$j] = Number($testfilearray1[$i][$j])
    Next
Next

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

_ArrayMultiColSort($testfilearray1, $aSortData)

_ArrayDisplay($testfilearray1, "", 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

 

Share this post


Link to post
Share on other sites

My apologies, I failed to notice that my posts were the last ones on the page so my responses were delayed.

Thank you for the clarification jchd, I suspected as much.

At least my hours spent generating my padding thing (I'm still unsure of the proper name) aren't entirely in vain as It has effectively set up a method of looping through only the columns to be sorted.

Share this post


Link to post
Share on other sites

Melba23

Not to criticize, but wouldn't it be more efficient to only make the columns that are to be sorted into number format? repurposing this section of code from my padding thing should do just that. Is there anything inherently wrong doing it this way that  should Know about?

This has the same requirements as my original padding thing on the previous page.

#Region Init
Local $testfilearray1[3][3] = [["123", "321", "-1"], ["123", "-31", "13"], ["123", "-321", "-12"]]
Local $testsize = UBound($testfilearray1) - 1
Global $aSortData[][] = [[1, 0], [2, 0]]
#EndRegion Init


#Region Make Numb
Local $sorttotalcount = UBound($aSortData)-1
For $sortcount = 0 To $sorttotalcount Step 1
    Local $colnum  = $aSortData[$sortcount][0]
    For $testfilerownum2 = 0 To $testsize Step 1
        $testfilearray1[$testfilerownum2][$colnum] = Number($testfilearray1[$testfilerownum2][$colnum])
    Next
Next
_ArrayDisplay($testfilearray1, "$testfilearray1")
#EndRegion

Share this post


Link to post
Share on other sites

Funtime60,

Quote

wouldn't it be more efficient to only make the columns that are to be sorted into number format?

Of course - in fact if you try to convert text string elements into numbers you will destroy them. I only looped through the whole array in my example because all columns in your original example were numeric.

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

 

Share this post


Link to post
Share on other sites

I have simply an array like that:

2 2
2 1
2 3
1 2
1 1
1 3

This is what i want:

1 1
1 2
1 3
2 1
2 2
2 3

I tried lots of codes above, nothing worked.

What my sort data should be? @Melba23

Edited by Adele

Share this post


Link to post
Share on other sites

Adele,

The secret is to get the sort data array correctly formatted:

#include "ArrayMultiColSort.au3"

Global $aArray[][] = [[2, 2], [2, 1], [2, 3], [1, 2], [1, 1], [1, 3]]

; Here is the original array
_ArrayDisplay($aArray, "Original", Default, 8)

; Set the order in which the columns are to be sorted and how to sort them
; First we sort col 0 in ascending order and then col 1 also in ascending order
Global $aSortData[][] = [[0, 0], [1, 0]]

; Sort the array
_ArrayMultiColSort($aArray, $aSortData)

; And here is the sorted one
_ArrayDisplay($aArray, "Sorted", Default, 8)

All clear now?

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

 

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

×
×
  • Create New...