Jump to content

Recommended Posts

Posted

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!

  Reveal hidden contents

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

  • Moderators
Posted

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

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:

  Reveal hidden contents

 

  • 1 year later...
Posted

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

  Reveal hidden contents

 

  • Moderators
Posted

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

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:

  Reveal hidden contents

 

Posted

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.

  Reveal hidden contents

 

Posted

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

  Reveal hidden contents

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)

Posted

True. But the documentation and code should match.

  Reveal hidden contents

 

Posted

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

  Reveal hidden contents

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)

  • Moderators
Posted

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

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:

  Reveal hidden contents

 

  • 2 months later...
  • Moderators
Posted

[New Release] - 15 Sep 15

Changed: UDF can now sort columns in any order.

New files and zip in first post.

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:

  Reveal hidden contents

 

  • 1 month later...
Posted

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?

  • Moderators
Posted

Bizzaro,

  Quote

Is this what your UDF does?

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

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:

  Reveal hidden contents

 

Posted (edited)

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

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

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

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:

  Reveal hidden contents

 

Posted

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.

 

  • 7 months later...
  • 1 year later...
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
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.

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
  • Recently Browsing   0 members

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