# _ArraySort

## Recommended Posts

The values are:

eg.

10 - 6 - 56 - 37 - 21

And i need transform the array in:

6 - 10 - 21 - 37 - 56

I try but return:

10 - 21 - 37 - 56 - 6

Note: I need the ascending.

That is, 6 can not be greater than 56

##### Share on other sites

It's sorting as text...first, loop through the array, and convert each element to Int(), then sort

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

##### Share on other sites

try this.

```#include <Array.au3>

;===============================================================================
; Example 1 (using a 1D array)
;===============================================================================
Local \$avArray[5] = [10,6 ,56 ,37 , 21]

_ArraySort(\$avArray)
_ArrayDisplay(\$avArray, "\$avArray AFTER _ArraySort() ascending")```
Edited by Danyfirex

AutoIt...

##### Share on other sites

allows you to pass in any sort function. Rather like C QSort would accept a pointer to the sort function.

Not only can you compare numerically if you want, your sort function can extract the sections of strings you want to compare. It's all done inline. No need to copy arrays in and out.

## 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

• ### Similar Content

• good morning everybody.
today i liked to share an small example with you
which it an function to read the registry values as an array
the result array is 2d array witch
\$a_array[n][0] = value name
\$a_array[n][1] = value Data
\$a_array[0][0] = values count
here's the function

#include <Array.au3> #include <WinAPIReg.au3> #include <APIRegConstants.au3> Local \$a_array = _RegReadToArray("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") If @error Then     MsgBox(16, "error", @error)     Exit EndIf _ArrayDisplay(\$a_array) Func _RegReadToArray(\$s_RegKey)     Local \$a_KeySplitInfo = StringSplit(\$s_RegKey, "\\", 2)     If UBound(\$a_KeySplitInfo) <= 1 Then         \$a_KeySplitInfo = StringSplit(\$s_RegKey, "\", 2)         If UBound(\$a_KeySplitInfo) <= 1 Then Return (1, 1, 0)     EndIf     Local \$H_KeyInfo = "", \$s_RegKeyInfo = ""     Switch \$a_KeySplitInfo[0]         Case "hklm", "HKEY_LOCAL_MACHINE", "hklm64", "HKEY_LOCAL_MACHINE64"             \$H_KeyInfo = \$HKEY_LOCAL_MACHINE         Case "hkCu", "HKEY_CURRENT_USER", "hkCU64", "HKEY_CURRENT_USER64"             \$H_KeyInfo = \$HKEY_CURRENT_USER         Case "hkCr", "HKEY_CLASSES_ROOT", "HKCR64", "HKEY_CLASSES_ROOT64"             \$H_KeyInfo = \$HKEY_CLASSES_ROOT         Case "HKU", "HKEY_USERS", "HKU64", "HKEY_USERS64"             \$H_KeyInfo = \$HKEY_USERS         Case Else             Return SetError(2, 2, 0)     EndSwitch     _ArrayDelete(\$a_KeySplitInfo, 0)     \$s_RegKeyInfo = _ArrayToString(\$a_KeySplitInfo, "\")     Local \$H_KeyInfoOpen = _WinAPI_RegOpenKey(\$H_KeyInfo, \$s_RegKeyInfo, \$KEY_READ)     Local \$A_KeyInfo = _WinAPI_RegQueryInfoKey(\$H_KeyInfoOpen)     If @error Then Return SetError(1, 1, 0)     _WinAPI_RegCloseKey(\$H_KeyInfoOpen)     Local \$A_RegVal[\$A_KeyInfo[2] + 1][2]     Local \$iV = 1, \$s_RegRead = ""     While 1         \$s_RegVal = RegEnumVal(\$s_RegKey, \$iV)         If @error <> 0 Then ExitLoop         \$s_RegRead = RegRead(\$s_RegKey, \$s_RegVal)         If Not (@error) Then             \$A_RegVal[\$iV][0] = \$s_RegVal             \$A_RegVal[\$iV][1] = \$s_RegRead         EndIf         \$iV += 1     WEnd     \$A_RegVal[0][0] = UBound(\$A_RegVal) - 1     If \$A_RegVal[0][0] >= 1 Then         Return \$A_RegVal     Else         Return SetError(3, 3, 0)     EndIf EndFunc   ;==>_RegReadToArray
i hope you benefit from it
with my greetings

• Hi, first of all thanks to all the guys who always help people in the forums, I wouldn't be able to do anything if wasn't for your help, even if I don't ask it myself.

I've created this code to get some info on a monitoring network on my work. It relays on _IETableGetCollection and _IETableWriteToArray.
It works well, but take around 3:25 minutes to get the info from 28 pages (some of them are large and take longer to load, but most of them are small and fast).
My question is if you see a way to get the program to go faster...

I've tried to make it easy for you to understand and edited somethings with sensitive info.
(Some of the pages doesn't have the black divider with MIRA in the end, so I need to search if it is there or not.)

#include <IE.au3> #include <array.au3> Local \$oIE = _IECreate("about:blank", 0, 0) Local \$paginas[28] = [89, 90, 91, 92, 93, 96, 105, 113, 119, 125, 126, 129, 131, 133, 135, 137, 139, 140, 141, 144, 145, 146, 148, 149, 150, 151, 158, 159] Local \$Datos_array[0][2] Local \$oTable Local \$tabla Local \$aux_x = 1 Local \$ar = 1 Local \$Numtables_datos = 0 MsgBox(0, "asd", "asd") For \$pag = 0 To UBound(\$paginas) - 1 Step 1 _IENavigate(\$oIE, "<WEBSITE URL>" & \$paginas[\$pag]) ; <<< the pages to load are always the same except for the last digits. _ArrayAdd(\$Datos_array, \$paginas[\$pag] & "|" & "Entrante", 0, "|") ; <<<<<<<<<<<<<<<< adds the page number toarray [0, 0] ;############################################ START counts amount of tables with traffic \$oTable = _IETableGetCollection(\$oIE) Local \$iNumTables = @extended For \$i = 3 To \$iNumTables - 2 Step 1 \$oTable = _IETableGetCollection(\$oIE, \$i) \$nomb_tabla2 = _IETableWriteToArray(\$oTable) ; <<<<<<<< TABLE TO ARRAY. \$string2 = StringStripWS(\$nomb_tabla2[1][0], 8) If \$string2 <> "MIRA" Then \$Numtables_datos = \$Numtables_datos + 1 Next \$tabla_End = \$iNumTables - \$Numtables_datos ;############################################ FIN \$tabla_Start = 4 \$tabla_trafico = 2 For \$for = 1 To \$Numtables_datos Step 1 \$oTable = _IETableGetCollection(\$oIE, \$tabla_Start - 1) ; <<<<<<<<<<< NAME OF THE TABLE; row2 = mira \$nomb_tabla = _IETableWriteToArray(\$oTable) ; <<<<<<<< TABLE TO ARRAY ;########################################### ADDS the traffic number into the row \$string = StringStripWS(\$nomb_tabla[1][0], 8) If \$string == "MIRA" Then ;si o si pasa por aca 1 vez _ArrayAdd(\$Datos_array, \$nomb_tabla[0][0]) \$nomb_aux = \$nomb_tabla[0][0] \$aux_x = 1 \$tabla_trafico = \$tabla_trafico + 2 Else ;esto deberia ser por row _ArrayAdd(\$Datos_array, \$nomb_aux & " " & \$aux_x) \$aux_x = \$aux_x + 1 \$tabla_trafico = \$tabla_trafico + 1 EndIf \$oTable = _IETableGetCollection(\$oIE, \$tabla_trafico) Local \$aTableData = _IETableWriteToArray(\$oTable) \$bps = _ArrayToString(\$aTableData, "|", 0, 0, @CRLF, 0, 0) \$bps = StringRight(\$bps, 5) \$bps = StringLeft(\$bps, 4) \$trafico_actual = _ArrayToString(\$aTableData, "|", 0, 0, @CRLF, 2, 2) If \$bps == "Gbps" Then \$trafico_actual = \$trafico_actual * 1000 If \$bps == "Kbps" Then \$trafico_actual = \$trafico_actual / 1000 \$Datos_array[\$ar][1] = \$trafico_actual \$ar = \$ar + 1 If \$string == "MIRA" Then \$tabla_Start = \$tabla_Start + 2 Else \$tabla_Start = \$tabla_Start + 1 EndIf Next \$ar = \$ar + 1 ;~ ############# CAÍDA ############ ;~ If \$actual_entrante = 0 Then ;~ \$xxx = 0 ;~ Do ;~ MsgBox(0, "Tráfico Caído", \$paginas[\$i], 5) ;~ \$xxx = \$xxx + 1 ;~ Until \$xxx = 10 ;~ EndIf ;~ ############# CAÍDA ############. Local \$Numtables_datos = 0 Next _ArrayDisplay(\$Datos_array, "Array display") _IEQuit(\$oIE) Thanks!!

monitoria.html
• By LWC
I have multiple network adapters but only one is actually connected.
I thus use @IPAddress1 in my scripts whereas @IPAddress2-4 return 0.0.0.0
But recently I've installed the VirtualBox emulator and it took over @IPAddress1 which means my real connection is now @IPAddress2.
Why is that? Is there a way to make AutoIt skip to @IPAddress2 if @IPAddress1 is used by an emulator?
In the attached screenshot it's temporarily disabled so I can revive my scripts which all already use @IPAddress1.

Update: here's the solution.
• By Skysnake
Hi
I am trying to set Accelerator keys from an array.
I select the KEY and CONTROL from a SQLite table, the Array looks like that generated for the Helpfile, but I can't get the CONTROLS to resolve...
I though about Assign & Eval, but not sure if that's a step in the right direction. IsDeclared shows that the \$var exists in Local Scope -1.

Local \$Main = GUICreate("Custom MsgBox", 225, 80) GUICtrlCreateLabel("Please select a button.", 10, 10) Local \$idButton_Yes = GUICtrlCreateButton("Yes", 10, 50, 65, 25) Local \$idButton_No = GUICtrlCreateButton("No", 80, 50, 65, 25) Local \$idButton_Exit = GUICtrlCreateButton("Exit", 150, 50, 65, 25) Local \$query, \$aResult, \$iRows, \$iColumns \$query = "" ;reset \$query = "Select hotkey_key, hotkey_ctrl from mytable where mykeys = 'hotkey' ; " ; ; Query \$iRval = _SQLite_GetTable2d(\$sqliteDb, \$query, \$aResult, \$iRows, \$iColumns) If \$iRval = \$SQLITE_OK Then Local \$sizeofHotkeys = UBound(\$aResult) - 1 ConsoleWrite("\$sizeofHotkeys " & \$sizeofHotkeys & @CRLF) If \$sizeofHotkeys > 0 Then Local \$main__aAccelKeys[\$sizeofHotkeys][2] For \$i = 0 To \$sizeofHotkeys - 1 \$j = \$i + 1 ; replace friendly text with code -- ! alt + Shift ^ Ctrl # Windows \$aResult[\$j][0] = StringReplace(\$aResult[\$j][0], "Alt", "!") \$aResult[\$j][0] = StringReplace(\$aResult[\$j][0], "Shift", "+") \$aResult[\$j][0] = StringReplace(\$aResult[\$j][0], "Ctrl", "^") \$main__aAccelKeys[\$i][0] = \$aResult[\$j][0] ;--- \$main__aAccelKeys[\$i][1] = \$aResult[\$j][1] ;--- Next ;~ Row|Col 0|Col 1 ;~ Row 0|F2|\$idButton_Yes ;~ Row 1|F3|\$idButton_No _DebugArrayDisplay(\$main__aAccelKeys) Local \$rv = GUISetAccelerators(\$main__aAccelKeys, \$Main) GUISetState(@SW_SHOW) ; Display the GUI.
Please note that this is a modified Helpfile example.
The Helpfile specifies (a) WinHandle and (b) last Gui created.
--> the example uses a control not a WinHandle and (b) what happens with ChildGuis? Also, the HelpFile specifies lower case, yet the examples show "{F1}" upper case?
Also, is there a way to check the result of the GuiSetAccelerator function?
Note, if I add these to lines after the FOR loop, then the F1 works, and the DebugArrayDisplays shows control 4... not it's name... So I am in the right place, but my \$vars names do not convert to their control numbers in the GUI
Next \$main__aAccelKeys[\$sizeofHotkeys - 1][0] = "{F1}" ; -- -- use the extra row for the F1 \$main__aAccelKeys[\$sizeofHotkeys - 1][1] = \$ChmHLP ;--- Skysnake
• By wolflake
Fruit
Col2 > Beef
Case "Beef" and \$aR[2] = 0
Beef1()
Case "Beef"
Beef2()
EndSwitch   On a technical note I attached the context menu to the window itself not a dummy control and I didn't use _GUICtrlMenu_TrackPopupMenu.  Instead I launched the context menu with "send shift-F10" and waited for GuiGetMsg() to give me the selection. Right click is picked up by GUIRegisterMsg WM_RBUTTONUP and Tooltips are done with GUIRegisterMsg WM_MENUSELECT. The whole thing is done with 3 functions.
I won't tell you how long it took me to figure this out but I'll say that on one of my early attempts it had two windows running at once and one was just to recieve the right click an tell the other it got it.  Suffice it to say I'm no wiz at Autoit but I really appreciate the support the community offers and I hope someone finds this useful. BTW I wrote a script to produce 1d and 2d auotit array code from excel in case you want to model your menu in excel. Here is the link.
https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1412314
#include "ArrayToMenu.au3" ;Simple 1d array with tooltips item separator and right click. \$aM = StringSplit("Zero,One,-,Two/Two_R", ",", 3) ;make an array for the menu items \$aT = StringSplit("Zero,One,-,", ",", 3) ;make an array for the menu Tooltips \$aR = _ArrayToMenu(\$aM,\$aT) if @error then ConsoleWrite(@error & @CRLF) EndIf ConsoleWrite("R: " & \$aR[0] & " " & "C: " & \$aR[1] & " " & "Rclick: " & \$aR[2] & " " & "Item: " & \$aR[3] & @CRLF) If \$aR[0] = -1 Then ;either hit escape or clicked on another window ConsoleWrite("Esc" & @CRLF) Exit EndIf ;_ArrayDisplay(\$aR) Switch \$aR[3] Case "Zero" Zero() Case "One" One() Case "Two/Two_R" And \$aR[2] = 0 ;No Rclick Two() Case "Two/Two_R" And \$aR[2] = 1 ;Rclick Two_R() EndSwitch Func Zero() ConsoleWrite("You chose: Zero" & @CRLF) EndFunc ;==>Zero Func One() ConsoleWrite("You chose: One" & @CRLF) EndFunc ;==>One Func Two() ConsoleWrite("You chose: Two" & @CRLF) EndFunc ;==>Two Func Two_R() ConsoleWrite("You chose: Two_R" & @CRLF) EndFunc ;==>Two_R Example 2 2d array with sub-menu
#include "ArrayToMenu.au3" ;2d array with a sub-menu dim \$aM[4][2] = [["Beef", "Orange"], ["Pork", "Apple"], ["Chicken", "Grape"], ["Fruit->", ""]] ;Note you don't need a tooltip for every item but you at least need a place holder in the array dim \$aT[4][2] = [["Red Meat", "Fruit"], ["Other white meat", "Fruit"], ["White meat", "Fruit"], ["", ""]] \$aR = _ArrayToMenu(\$aM,\$aT) if @error Then ConsoleWrite(@error & @CRLF) Exit EndIf If \$aR[0] = -1 Then ConsoleWrite("Esc" & @CRLF) Exit EndIf ConsoleWrite("R: " & \$aR[0] & " " & "C: " & \$aR[1] & " " & "Rclick: " & \$aR[2] & " " & "Item: " & \$aR[3] & @CRLF) Switch \$aR[3] Case "Beef" Beef() Case "Pork" Pork() Case "Chicken" Chicken() Case "Orange" ConsoleWrite("Oranges are good for you!" & @CRLF) ConsoleWrite("Oranges" & " \$aR[0] = " & \$aR[0] & " \$aR[1] = " & \$aR[1] & @CRLF) Case "Apple" ConsoleWrite("Apples are good for you!" & @CRLF) Case "Grape" ConsoleWrite("Grapes are good for you!" & @CRLF) EndSwitch Func Beef() ConsoleWrite("Beef" & " \$aR[0] = " & \$aR[0] & " \$aR[1] = " & \$aR[1] & @CRLF) EndFunc ;==>Beef Func Pork() ConsoleWrite("Pork" & " \$aR[0] = " & \$aR[0] & " \$aR[1] = " & \$aR[1] & @CRLF) EndFunc ;==>Pork Func Chicken() ConsoleWrite("Chicken" & @CRLF) EndFunc ;==>Chicken
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...