Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/26/2019 in all areas

  1. Gianni

    BrowserControl Companion

    Making the integration between AutoIt and the BrowserControl easier may facilitate the development of interesting programs. Just think of all those (fantastic) libraries and frameworks available for javascript that could be integrated and exploited in an AutoIt program. For example, to graphically present the results of an AutoIt processing in the GUI, ... and many other possibilities. Providing the basic functions to implement this synergistic interaction is the purpose of this post (if for no other reason, just even to collect some tests done over time here and there, so as not to leave them scattered and easily find them in just one place) In this UDF there are only a few functions (or better if called wrappers), but I hope to add more as I go and, even better, to receive suggestions and advice on new features and techniques to improve and expand it. _WebBrowser_GUICtrlCreate Create an Internet Explorer 'Browser Control' _WebBrowser_SetHTML Set a new HTML listing in the BrowserControl _WebBrowser_CSS_Inject Creates into the html document a CSS node element with embedded the passed CSS _WebBrowser_JS_Inject Creates into the html document a javascript node element with embedded the passed javascript _WebBrowser_JS_Eval Evaluates a passed string as JavaScript code and executes it _WebBrowser_JS_setTimeout Calls a javascript function or executes a javascript code snippet [option after a specified delay] _WebBrowser_JS_ElementGetRef Retrieves a reference to an element suitable to be used from AutoIt _WebBrowser_ExecuteDotNotation Get a reference to an object's child member or the value of a property, by means of a dotted path _WebBrowser_BasicHTML Returns a basic html page listing (a little enhanced than about:blank) The three examples provided in the attached ziped file are a bit 'improvised' and do not take advantage of all the possibilities offered by the underlying javascript libraries used. They are just three "hello world" scripts to test the ABC of the interaction with the "BrowserControl". (ToDo: Interaction with javascript custom events) Bug reports, creative criticisms and suggestions (particularly regarding the interaction with javascript custom events) are welcome I hope you can have fun with the Browser Control BrowserControl.zip
    2 points
  2. Addition : I have written a small test script for people who are interested to compare the versions of @trancexx and @Ascer . You can 'play around' with it and make your own decision . #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <StringConstants.au3> Opt("MustDeclareVars", 1) Global $g_sEncoded, $g_sDecoded, $g_sString, $g_iTime ; Bigtext : Global $g_sString = BinaryToString(InetRead("https://www.autoitscript.com/forum/"), 4) ;~ Global $g_sString = "Hello World, öäü ÖÄÜ ß" ; for simple tests ConsoleWrite(@CRLF) ConsoleWrite("+ >> StringLen = " & StringLen($g_sString) & @CRLF) ; ----------- Trancexx : --------------- ConsoleWrite(@CRLF) ConsoleWrite("+ >>>>> Trancexx <<<<< :" & @CRLF) ; Encode : $g_iTime = TimerInit() $g_sEncoded = _Base64Encode($g_sString) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Trancexx Encoding Time", $g_iTime)) ConsoleWrite(@CRLF) ; Decode : $g_iTime = TimerInit() $g_sDecoded = _Base64Decode($g_sEncoded) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Trancexx Decoding Time", $g_iTime)) ConsoleWrite(@CRLF) ; !!! don't use this for long strings - better write to file : ConsoleWrite($g_sEncoded & @CRLF) ConsoleWrite(BinaryToString($g_sDecoded) & @CRLF) ; ----------- Ascer : --------------- ConsoleWrite(@CRLF) ConsoleWrite("+ >>>>> Ascer <<<<< :" & @CRLF) ; Encode : $g_iTime = TimerInit() $g_sEncoded = base64($g_sString) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Ascer Encoding Time ", $g_iTime)) ConsoleWrite(@CRLF) ; Decode : $g_iTime = TimerInit() $g_sDecoded = base64($g_sEncoded, False) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Ascer Decoding Time ", $g_iTime)) ConsoleWrite(@CRLF) ; !!! don't use this for long strings - better write to file : ConsoleWrite($g_sEncoded & @CRLF) ConsoleWrite(BinaryToString($g_sDecoded) & @CRLF) ; ======================= Functions : ========================= ;--------------------------------------------------------------------------------- ; Trancexx : Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode Func _Base64Decode($input_string) Local $struct = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error decoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode ;--------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------- ; Ascer ;============================================================================================================================== ; Function: base64($vCode [, $bEncode = True [, $bUrl = False]]) ; ; Description: Decode or Encode $vData using Microsoft.XMLDOM to Base64Binary or Base64Url. ; IMPORTANT! Encoded base64url is without @LF after 72 lines. Some websites may require this. ; ; Parameter(s): $vData - string or integer | Data to encode or decode. ; $bEncode - boolean | True - encode, False - decode. ; $bUrl - boolean | True - output is will decoded or encoded using base64url shema. ; ; Return Value(s): On Success - Returns output data ; On Failure - Returns 1 - Failed to create object. ; ; Author (s): (Ghads on Wordpress.com), Ascer ;=============================================================================================================================== Func base64($vCode, $bEncode = True, $bUrl = False) Local $oDM = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oDM) Then Return SetError(1, 0, 1) Local $oEL = $oDM.createElement("Tmp") $oEL.DataType = "bin.base64" If $bEncode then $oEL.NodeTypedValue = Binary($vCode) If Not $bUrl Then Return $oEL.Text Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "") Else If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/") $oEL.Text = $vCode Return $oEL.NodeTypedValue EndIf EndFunc ;==>base64 ;--------------------------------------------------------------------------------- My result : The version from trancexx is faster. With extremely long strings, the version from Ascer caused an error message during decoding (on my system).
    2 points
  3. Gianni

    festive lighting

    just a simple festive decoration for our screen Happy holidays to all! p.s. to turn it off just click on any "light" and then press esc #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Global $aColors = StringSplit("0x000000,0x0000AA,0x00AA00,0x00AAAA,0xAA0000,0xAA00AA,0xAAAA00,0xAAAAAA,0x555555,0x0000FF,0x00FF00,0x00FFFF,0xFF0000,0xFF00FF,0xFFFF00,0xFFFFFF", ',', 2) Global $iColors = UBound($aColors) - 1 Global $iX = @DesktopWidth, $iY = @DesktopHeight Global $iNrX = Int($iX/17), $iNrY = Int($iY/17) - 2 Global $hGui1 = GUICreate("", $iX, 17, 0, 0, $WS_POPUPWINDOW, $WS_EX_TOPMOST) ; top bar Global $idListview1 = GUICtrlCreateListView("", 0, 0, $iX, 17) GUICtrlSetStyle($idListview1, BitOR($LVS_ICON, $LVS_NOSCROLL)) GUISetState() Global $hGui2 = GUICreate("", 17, $iY - 17 - 17 , 0, 17, $WS_POPUPWINDOW, $WS_EX_TOPMOST) ; left bar Global $idListview2 = GUICtrlCreateListView("", 0, 0, 17, $iY - 17 - 17) GUICtrlSetStyle($idListview2, BitOR($LVS_ICON, $LVS_NOSCROLL)) GUISetState() Global $hGui3 = GUICreate("", $iX, 17, 0, $iY - 17, $WS_POPUPWINDOW, $WS_EX_TOPMOST) ; bottom bar Global $idListview3 = GUICtrlCreateListView("", 0, 0,$iX, 17) GUICtrlSetStyle($idListview3, BitOR($LVS_ICON, $LVS_NOSCROLL)) GUISetState() Global $hGui4 = GUICreate("", 17, $iY -17 -17, $iX - 17 , 17, $WS_POPUPWINDOW, $WS_EX_TOPMOST) ; right bar Global $idListview4 = GUICtrlCreateListView("", 0, 0,17, $iY -17 -17) GUICtrlSetStyle($idListview4, BitOR($LVS_ICON, $LVS_NOSCROLL)) GUISetState() Global $hImage = _GUIImageList_Create() For $i = 0 To $iColors _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview1, $aColors[$i], 16, 16)) Next _GUICtrlListView_SetImageList($idListview1, $hImage) _GUICtrlListView_SetImageList($idListview2, $hImage) _GUICtrlListView_SetImageList($idListview3, $hImage) _GUICtrlListView_SetImageList($idListview4, $hImage) For $x = 1 To $iNrX _GUICtrlListView_AddItem($idListview1, '', Random(0, $iColors, 1)) _GUICtrlListView_AddItem($idListview3, '', Random(0, $iColors, 1)) Next For $y = 1 To $iNrY _GUICtrlListView_AddItem($idListview2, '', Random(0, $iColors, 1)) _GUICtrlListView_AddItem($idListview4, '', Random(0, $iColors, 1)) Next _GUICtrlListView_SetIconSpacing($idListview1, 16 + 1, 16 + 1) _GUICtrlListView_Arrange($idListview1) _GUICtrlListView_SetIconSpacing($idListview2, 16 + 1, 16 + 1) _GUICtrlListView_Arrange($idListview2) _GUICtrlListView_SetIconSpacing($idListview3, 16 + 1, 16 + 1) _GUICtrlListView_Arrange($idListview3) _GUICtrlListView_SetIconSpacing($idListview4, 16 + 1, 16 + 1) _GUICtrlListView_Arrange($idListview4) _GUICtrlListView_EndUpdate($idListview1) Do _GUICtrlListView_SetItem($idListview1, '', Random(0, $iNrX, 1), 0, Random(0, $iColors, 1)) _GUICtrlListView_SetItem($idListview3, '', Random(0, $iNrX, 1), 0, Random(0, $iColors, 1)) _GUICtrlListView_SetItem($idListview2, '', Random(0, $iNrY, 1), 0, Random(0, $iColors, 1)) _GUICtrlListView_SetItem($idListview4, '', Random(0, $iNrY, 1), 0, Random(0, $iColors, 1)) WinSetOnTop($hGui1, '', 1) WinSetOnTop($hGui2, '', 1) WinSetOnTop($hGui3, '', 1) WinSetOnTop($hGui4, '', 1) Until GUIGetMsg() = $GUI_EVENT_CLOSE
    1 point
  4. @Nine this is exactly what I needed and your script works perfectly! Thank you so much for sharing this. I was able to shorten the timer down to 5 seconds because the folder I'm watching is small. @Danp2 this is just an example of the folder I'm using - I just threw the temp folder in there as an example.
    1 point
  5. #include "Json.au3" TestThis() Func TestThis() Local $myJson = '{"response":{"userid":"4798","success":1}}' Json_Dump($myJson) ; to get what you look for Local $oTemp = Json_Decode($myJson) Local $my_userid = Json_ObjGet($oTemp, ".response.userid") ; use what you look for here Local $my_success = Json_ObjGet($oTemp, ".response.success") ConsoleWrite('- $my_userid = "' & $my_userid & '"' & @CRLF) ConsoleWrite('- $my_success = ' & $my_success & @CRLF) EndFunc
    1 point
  6. Your JSON example is invalid. Just plug it into any JSON validator on the web and you will see. It most likely should have been something like: {"response":{"userid":"4798","success":1}} Correct your JSON and try again. Use the json_dump() function to get an idea of how to reference json values using the dot-notation. #include <MyIncludes\json\json.au3> ;<== Change to your location $data = '{"response":{"userid":"4798","success":1}}' Json_Dump($data) $object = json_decode($data) $message=json_get($object,".response.userid") ;using dot-notation ;~ $message=json_get($object,"[response][userid]") ;using bracket-notation MsgBox("","Test",$message) Output: +-> .response.userid =4798 +-> .response.success =1 @auitden: I updated my response with an example using your original script snippet.
    1 point
  7. When in Scite, press Alt+m and Ctrl-F9...
    1 point
  8. Windows 10 try the following basic example: #include <Array.au3> #include <StringConstants.au3> #include <WinAPIProc.au3> Opt("ExpandEnvStrings", 1) ShellExecute(@ScriptDir & "\KillingInTheName.mp3") Local $iMP3Player, $sMP3Default = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mp3\UserChoice", "ProgId") Local $sMP3Player = RegRead("HKCR\" & $sMP3Default & "\shell\open\command", "") If $sMP3Player = "" Then $sMP3Player = RegRead("HKCR\" & $sMP3Default & "\shell\open", "PackageId") Else $sMP3Player = StringRegExp($sMP3Player, '^"(.+?)"', $STR_REGEXPARRAYMATCH)[0] EndIf Local $aList = ProcessList() ReDim $aList[$aList[0][0] + 1][3] For $i = 1 To $aList[0][0] $aList[$i][2] = _WinAPI_GetProcessFileName($aList[$i][1]) If StringInStr($aList[$i][2], $sMP3Player) Then $iMP3Player = $aList[$i][1] ConsoleWrite(".Mp3 Process Name = " & $aList[$i][0] & @CRLF) ConsoleWrite(".Mp3 PID = " & $aList[$i][1] & @CRLF) ConsoleWrite(".Mp3 Process Path = " & $aList[$i][2] & @CRLF) ExitLoop EndIf Next
    1 point
  9. Nine

    Save Label Area to PNG

    Case $idButtonExport $tRect = _WinAPI_GetWindowRect (ControlGetHandle($hGUI, "", $idOutput)) $iLeft = DllStructGetData ($tRect,"left") $iTop = DllStructGetData ($tRect,"top") $iRight = DllStructGetData ($tRect,"right") $iBottom = DllStructGetData ($tRect,"bottom") _ScreenCapture_Capture ("Test.png",$iLeft, $iTop, $iRight, $iBottom)
    1 point
  10. This is flat-out wrong. On Windows, the algorithm to generate PIDs is intentionally undocumented, it may change from OS version to version, and unlike on *nix, it is NOT sequential.
    1 point
  11. Check out ProcessList You can run it after your run command for the name of your application. Sort the list to get them in PID sequence, I'm guessing the last process will be the highest PID (not guaranteed). Alternatively (and more robustly) if your process takes a file name as an argument, change your Run line to avoid the whole cmd shell creation and execute the media player with the file as a command line option directly, then you will get the correct PID returned. I also just saw this: Which looks like a lot of effort for what you want.... I see it is pretty old and I've not used it. G'luck.
    1 point
  12. Another way to sort a 2D array by multiple columns is binary sorting based on an index. That is, the row numbers are inserted in the index at positions corresponding to the sorting order. The array itself is not affected by the sorting. Func SortArray( ByRef $aItems, $pIndex, $tIndex, $aCmps ) Local $iCmps = UBound( $aCmps ), $c, $r, $v[$iCmps] Local $lo, $hi, $mi For $i = 0 To UBound( $aItems ) - 1 For $j = 0 To $iCmps - 1 $v[$j] = $aItems[$i][$aCmps[$j][0]] ; Values Next $lo = 0 $hi = $i - 1 While $lo <= $hi ; Binary search $r = 0 ; Compare result (-1,0,1) $j = 0 ; Index in $aCmps array $mi = Int( ( $lo + $hi ) / 2 ) While Not $r And $j < $iCmps ; This While-loop handles sorting by multiple $c = $aCmps[$j][0] ; Column ; columns. Column values of the two rows are Switch $aCmps[$j][1] ; Number/string ; compared until a difference is found. Case 0 ; Compare column values as numbers. The following line is an implementation of the spaceship or three-way comparison operator for numbers like StringCompare is for strings. $r = ( $v[$j] < $aItems[DllStructGetData($tIndex,1,$mi+1)][$c] ? -1 : $v[$j] = $aItems[DllStructGetData($tIndex,1,$mi+1)][$c] ? 0 : 1 ) * $aCmps[$j][2] ; * $iCmpAsc Case 1 ; Compare column values as strings. StringCompare is a spaceship or three-way comparison operator for strings. $r = StringCompare( $v[$j], $aItems[DllStructGetData($tIndex,1,$mi+1)][$c] ) * $aCmps[$j][2] ; * $iCmpAsc EndSwitch $j += 1 WEnd Switch $r Case -1 $hi = $mi - 1 Case 1 $lo = $mi + 1 Case 0 ; Equal ExitLoop EndSwitch WEnd If $i > $mi Then _ ; Make space for the row number in index DllCall( $hKernel32Dll, "none", "RtlMoveMemory", "struct*", $pIndex+($mi+1)*4, "struct*", $pIndex+$mi*4, "ulong_ptr", ($i-$mi)*4 ) DllStructSetData( $tIndex, 1, $i, $mi+1+($lo=$mi+1) ) ; Insert row number $i at position $mi+1+($lo=$mi+1) in index Next EndFunc Example: #include <Array.au3> Opt( "MustDeclareVars", 1 ) Global Const $hKernel32Dll = DllOpen( "kernel32.dll" ) Example( 1000, 3 ) Func Example( $iRows, $iCols ) Local $aItems[$iRows][$iCols] ; Fill array FillArray( $aItems ) _ArrayDisplay( $aItems, "Unsorted" ) ; Sort array Local $tIndex = DllStructCreate( "uint[" & $iRows & "]" ) Local $pIndex = DllStructGetPtr( $tIndex ) Local $aCmps[3][3] = [ _ [ 0, 1, +1 ], _ ; Col 0: Compared as strings, asc [ 1, 0, +1 ], _ ; Col 1: Compared as numbers, asc [ 2, 0, +1 ] ] ; Col 2: Compared as numbers, asc SortArray( $aItems, $pIndex, $tIndex, $aCmps ) ; Display rows Local $iRows2 = $iRows, $j Local $aItems2[$iRows2][$iCols] For $i = 0 To $iRows2 - 1 $j = DllStructGetData($tIndex,1,$i+1) For $k = 0 To $iCols - 1 $aItems2[$i][$k] = $aItems[$j][$k] Next Next _ArrayDisplay( $aItems2, "Sorted" ) EndFunc DllClose( $hKernel32Dll ) Func FillArray( ByRef $aItems ) Local $aLetters[26] = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', _ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ] Local $s, $t, $iRows = UBound( $aItems ) For $i = 0 To $iRows - 1 $s = $aLetters[Random(0,25,1)] For $j = 1 To 9 $s &= $aLetters[Random(0,25,1)] Next $aItems[$i][0] = $s ; String $aItems[$i][1] = Random( 0, $iRows - 1, 1 ) ; Integer $aItems[$i][2] = Random( 0, $iRows - 1, 1 ) + Round( Random(), 4 ) ; Float ; Duplicate strings For $j = 1 To Random(0,2,1) If $i = $iRows - 1 Then ExitLoop $i += 1 $aItems[$i][0] = $s ; String $aItems[$i][1] = Random( 0, $iRows - 1, 1 ) ; Integer $aItems[$i][2] = Random( 0, $iRows - 1, 1 ) + Round( Random(), 4 ) ; Float $t = $aItems[$i][1] ; Duplicate strings and integers For $m = 1 To Random(0,2,1) If $i = $iRows - 1 Then ExitLoop $i += 1 $aItems[$i][0] = $s ; String $aItems[$i][1] = $t ; Integer $aItems[$i][2] = Random( 0, $iRows - 1, 1 ) + Round( Random(), 4 ) ; Float Next Next Next EndFunc Func SortArray( ByRef $aItems, $pIndex, $tIndex, $aCmps ) Local $iCmps = UBound( $aCmps ), $c, $r, $v[$iCmps] Local $lo, $hi, $mi For $i = 0 To UBound( $aItems ) - 1 For $j = 0 To $iCmps - 1 $v[$j] = $aItems[$i][$aCmps[$j][0]] ; Values Next $lo = 0 $hi = $i - 1 While $lo <= $hi ; Binary search $r = 0 ; Compare result (-1,0,1) $j = 0 ; Index in $aCmps array $mi = Int( ( $lo + $hi ) / 2 ) While Not $r And $j < $iCmps ; This While-loop handles sorting by multiple $c = $aCmps[$j][0] ; Column ; columns. Column values of the two rows are Switch $aCmps[$j][1] ; Number/string ; compared until a difference is found. Case 0 ; Compare column values as numbers. The following line is an implementation of the spaceship or three-way comparison operator for numbers like StringCompare is for strings. $r = ( $v[$j] < $aItems[DllStructGetData($tIndex,1,$mi+1)][$c] ? -1 : $v[$j] = $aItems[DllStructGetData($tIndex,1,$mi+1)][$c] ? 0 : 1 ) * $aCmps[$j][2] ; * $iCmpAsc Case 1 ; Compare column values as strings. StringCompare is a spaceship or three-way comparison operator for strings. $r = StringCompare( $v[$j], $aItems[DllStructGetData($tIndex,1,$mi+1)][$c] ) * $aCmps[$j][2] ; * $iCmpAsc EndSwitch $j += 1 WEnd Switch $r Case -1 $hi = $mi - 1 Case 1 $lo = $mi + 1 Case 0 ; Equal ExitLoop EndSwitch WEnd If $i > $mi Then _ ; Make space for the row number in index DllCall( $hKernel32Dll, "none", "RtlMoveMemory", "struct*", $pIndex+($mi+1)*4, "struct*", $pIndex+$mi*4, "ulong_ptr", ($i-$mi)*4 ) DllStructSetData( $tIndex, 1, $i, $mi+1+($lo=$mi+1) ) ; Insert row number $i at position $mi+1+($lo=$mi+1) in index Next EndFunc Or you can download this file if you prefer: Sort.au3 I have tested how long time the three methods (_ArrayMultiColSort by Melba23, SQLite sort by Chimp, and the method above) takes to sort six arrays with 10,000/50,000 rows and 3/6/9 columns. The arrays are sorted by column 0 (strings), 1 (integers) and 2 (reals). Column 0 and 1 contains a relatively large number of duplicates. Results for 10,000 rows: $aItems[10000][3] $aItems[10000][6] $aItems[10000][9] Fill array ... Fill array ... Fill array ... Fill array ... done Fill array ... done Fill array ... done Sort by index ... Sort by index ... Sort by index ... Time: 1217.88761269971 Time: 1248.21605830786 Time: 1236.41466104082 Sort by index ... done Sort by index ... done Sort by index ... done Sort by SQLite ... Sort by SQLite ... Sort by SQLite ... Time: 2635.69246331332 Time: 3543.51988465855 Time: 4398.68212872624 Sort by SQLite ... done Sort by SQLite ... done Sort by SQLite ... done Sort by _ArrayMultiColSort ... Sort by _ArrayMultiColSort ... Sort by _ArrayMultiColSort ... Time: 1146.7832396923 Time: 1521.86873177777 Time: 1831.70970213038 Sort by _ArrayMultiColSort ... done Sort by _ArrayMultiColSort ... done Sort by _ArrayMultiColSort ... done Results for 50,000 rows: $aItems[50000][3] $aItems[50000][6] $aItems[50000][9] Fill array ... Fill array ... Fill array ... Fill array ... done Fill array ... done Fill array ... done Sort by index ... Sort by index ... Sort by index ... Time: 7166.40803514761 Time: 7174.31887542089 Time: 7188.0017143575 Sort by index ... done Sort by index ... done Sort by index ... done Sort by SQLite ... Sort by SQLite ... Sort by SQLite ... Time: 13285.8896390571 Time: 17742.5454596211 Time: 21928.3266376507 Sort by SQLite ... done Sort by SQLite ... done Sort by SQLite ... done Sort by _ArrayMultiColSort ... Sort by _ArrayMultiColSort ... Sort by _ArrayMultiColSort ... Time: 6216.31940253656 Time: 8181.67386319132 Time: 10040.1219591297 Sort by _ArrayMultiColSort ... done Sort by _ArrayMultiColSort ... done Sort by _ArrayMultiColSort ... done All necessary code to repeat the tests is included in the zip: Sorting.7z. Run Test.au3. I'm interested in this topic because I need a quick way to sort and maintain (large) arrays in Virtual listviews for huge number of rows.
    1 point
  13. to simplify a bit your life, you could use sql against your 2d array so to get your wanted result using an SQL query and leave the SQLite engine will work for you. You need to download the ArraySQL udf from this post ( https://www.autoitscript.com/forum/topic/166536-manage-arrays-by-means-of-sql/?do=findComment&comment=1234441 ), and then use something like this for example: #include <Array.au3> #include <ArraySQL.au3> ; <-- download this from following post: ; https://www.autoitscript.com/forum/topic/166536-manage-arrays-by-means-of-sql/?do=findComment&comment=1234441 Local $ar[200][5] For $i = 0 To 199 For $j = 0 To 4 ; Short random data to only one char so to better see the logic of the result. $ar[$i][$j] = Chr(Random(97, 122, 1)) ; &Chr(Random(97,122,1))&Chr(Random(97,122,1)) Next Next _ArrayDisplay($ar, "$ar BEFORE _ArraySort()") #cs For $i = 3 to 0 step -1 if not _ArraySort($ar,0,0,0,$i) Then MsgBox('','error',@error) EndIf _ArrayDisplay($ar, "$ar AFTER _ArraySort() ascending column "&$i) Next #ce ; returns all rows ordered first by column3 then by Column2, column1 and Column0) $sQuery = "SELECT * FROM array ORDER BY column3,column2,column1,column0;" $aResult = _ArraySQL($ar, $sQuery) If Not @error Then _ArrayDisplay($aResult, "Ordered by column3,column2,column1,column0") Else MsgBox(0, "error", $g__sSQLiteError) EndIf
    1 point
×
×
  • Create New...