Jump to content

_ArraySort problem


Recommended Posts

So I've made this script that detects how long i have held down my left mouse button for and stores the information in an array and then sorts its using _ArraySort but the output is half sorted half broken.

Here's my script:

HotKeySet("{F1}","_exit")
#include <Misc.au3>
#include <Timers.au3>
#include <Array.au3>

Local $dll = DllOpen("user32.dll")
$on = False
Global $array[0]

While(1)
    If _IsPressed(01,$dll) Then
        $timer = _Timer_Init()
        While _IsPressed(01,$dll)
            Sleep(1)
        WEnd
        $time = _Timer_Diff($timer)
        _ArrayAdd($array,"Time: " & Floor($time) & " ms")
;~      ConsoleWrite("Time: " & Floor($time) & " ms" & @CRLF)
    EndIf
    Sleep(50)
WEnd

Func _exit()
    _ArraySort($array)
    _ArrayDisplay($array)
    Exit
EndFunc

And the output:

o5X6YHZ.png

See how its not sorted?  What is the problem here?

Link to comment
Share on other sites

It's sorting alphanumerically, because you stored strings. Instead, store only the time in ms (numerically, not as string!) .

Link to comment
Share on other sites

  • Moderators

TrashBoat,

_ArraySort sorts strings alphabetically - which is why you get what you do as a result. Save the values as numbers and it will sort numerically:

_ArrayAdd($array, Floor($time))

And if you open the DLL, you should really use DLLClose as you exit to shut it down.

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

  • Moderators

TrashBoat,

Actually AutoIt will clear up after you automatically - but doing it yourself is a good habit to get into and can save problems later on when you really do need to do so (such as with many GDI functions).

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

19 minutes ago, TrashBoat said:

does me not closing the dll result in memory loss

It's the other way around; if you suffer from memory loss you may forget to close the handle.;)

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

×
×
  • Create New...