# Search the Community

Showing results for tags 'sort'.

• ### Search By Tags

Type tags separated by commas.

### Forums

• General
• Announcements and Site News
• AutoIt v3
• AutoIt Help and Support
• AutoIt Technical Discussion
• AutoIt Example Scripts
• Scripting and Development
• Developer General Discussion
• Language Specific Discussion
• Operating System Deployment
• Windows Client
• Windows Server
• Office

### Categories

• AutoIt Team
• Beta
• MVP
• AutoIt
• Automation
• Databases and web connections
• Data compression
• Encryption and hash
• Games
• Hardware
• Information gathering
• Internet protocol suite
• Maths
• Media
• PDF
• Security
• Social Media and other Website API
• Windows
• Scripting and Development
• Operating System Deployment
• Windows Client
• Windows Server
• Office

• Forum FAQ
• AutoIt

### Calendars

• Community Calendar

• 0 Replies

• 0 Reviews

• 0 Views

Found 19 results

1. ## Array sort by length (1D)

Code is simple/selfexplanatory ... #include "Array.au3" \$a = StringSplit('aaa,b,cc', ',', 2) ; no_count _ArraySortLen(\$a) _ArrayDisplay(\$a, '\$a - without count') \$b = StringSplit('aaa,b,cc', ',') _ArraySortLen1(\$b) _ArrayDisplay(\$b, '\$b - with count') ; zero based array (without count at [0]) Func _ArraySortLen(ByRef \$aArr, \$iDescending = 0) Local \$j = UBound(\$aArr)-1 Local \$aTemp[\$j+1][2] For \$i = 0 To \$j \$aTemp[\$i][0] = StringLen(\$aArr[\$i]) \$aTemp[\$i][1] = \$aArr[\$i] Next _ArraySort(\$aTemp,\$iDescending) For \$i = 0 To \$j \$aArr[\$i] = \$aTemp[\$i][1] Next EndFunc ; one based array (with count at [0]) Func _ArraySortLen1(ByRef \$aArr, \$iDescending = 0) Local \$j = \$aArr[0] Local \$aTemp[\$j+1][2] For \$i = 1 To \$j \$aTemp[\$i][0] = StringLen(\$aArr[\$i]) \$aTemp[\$i][1] = \$aArr[\$i] Next _ArraySort(\$aTemp,\$iDescending,1) For \$i = 1 To \$j \$aArr[\$i] = \$aTemp[\$i][1] Next EndFunc

3. ## _arraysort numerically

Hi, i have this array of numbers in the form of strings, and i assumed _arraysort would sort them out, but theres no option to do it numerically, so i had to do it another way, seems clumsy, what am i missing here? There's for sure a better way to sort this out numerically right? _arraysort is doing a mess with the numbers, it goes like this: 35,45,50,42,48,54 #include<Array.au3> Local \$ID, \$AM Local \$FO = Fileopen('mult.txt') Local \$FR = FileReadToArray(\$FO) FileClose(\$FO) _ArrayDisplay(\$FR) For \$d = 0 To UBound(\$FR) \$AM = _ArrayMin(\$FR, 1) ConsoleWrite(\$AM &@CRLF) \$ID = _ArraySearch(\$FR, \$AM) _ArrayDelete(\$FR, \$ID) Next So this way i retrieve the lowest number and then delete it from the array, what would you do? mult.txt
4. ## double arraysort

Hi, Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y). I did not put much efffort into error checking but so far I did not need it. For my applications so far it works perfectly however if someone is willing I want to test this extensivly. If anyone has big lists of random stuff to sort could you try this out please? #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref \$array[, \$first_index = Default[, \$second_index = Default[, \$ascending = Default]]]) ; Parameters ....: \$array - 2d array to sort. ; \$first_index - [optional] first column to sort. Default is 0. ; \$second_index - [optional] second column to sort. Default is 1. ; \$ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref \$array, \$first_index = Default, \$second_index = Default, \$ascending = Default) Local \$temp_value Local \$counter = 1 If UBound(\$array, \$UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If \$first_index = Default Then \$first_index = 0 If \$second_index = Default Then \$second_index = 1 If \$ascending = Default Then \$ascending = 1 _ArraySort(\$array, \$ascending, 0, 0, \$first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf \$temp_value = \$array[0][\$first_index] For \$x = 1 to UBound(\$array, 1) - 1 If Mod( \$x, 10000) = 0 Then ConsoleWrite("at " & \$x & " of a total : " & UBound(\$array, 1) & @CRLF) If \$array[\$x][\$first_index] = \$temp_value Then \$counter+= 1 If \$x = UBound(\$array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort(\$array, \$ascending, \$x - \$counter, \$x, \$second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If \$counter > 0 Then ;at least 2 of the same _ArraySort(\$array, \$ascending, \$x - \$counter, \$x - 1, \$second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf \$counter = 1 EndIf EndIf \$temp_value = \$array[\$x][\$first_index] Next Return 1 EndFunc Kind regards, Ternal
5. ## _ArrayDisplay column sorting?

The help text for the _ArrayDisplay function says: "Clicking on a column header sort it." I'm wondering why the sorting of hex numbers (specifically window handles like 0x12345678) is so wonky. Sample script: #include <Array.au3> Local \$aList = WinList() _ArrayDisplay(\$aList) Clicking on the Col1 header to sort by window handle doesn't properly sort the list. As a workaround, I'm sorting the array by window handle before displaying it using _ArraySort. But I still wonder what's up with the ListView sorting. Workaround: #include <Array.au3> Local \$aList = WinList() _ArraySort(\$aList, 0, 1, 0, 1) _ArrayDisplay(\$aList)
6. ## Keep number format in sorted ListView, stringformat on sort

I am tracking this topic by @LarsJ. It is very advanced and overkill for what I am currently trying to do. Problem is this. Listview contains columns, one of which is right aligned and gets populated by float values, such as 123.99. Some do not have decimals ie 124.00 and on sort gets truncated to 124. Its obviously still the same value, but the display has reset. ; line below is for list VIEW ;..................................0.........1......2............ \$cListView = GUICtrlCreateListView("CUSTOMER|AMOUNT|DESCRIPTION", 8, 152, 764, 279) GUICtrlSetBkColor(\$cListView, \$GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color GUICtrlSetBkColor(\$cListView, \$LVStdClr) ; Set the background color for the listview _GUICtrlListView_SetColumnWidth(\$cListView, 0, 120) ; -- the client name _GUICtrlListView_SetColumnWidth(\$cListView, 1, 90) ;-- the amount _GUICtrlListView_JustifyColumn(\$cListView, 1, 1) ; 1 - Text is right aligned _GUICtrlListView_SetColumnWidth(\$cListView, 2, 200) ; the description What I am looking for is something native and simple like a _GUICtrlListView_SetColumnFormat(\$cListView, 1, "%.2f") ; 1 - column is stringformatted to "%.2f" So that after each sort it will appear as it was in the original rendering. Is there something like this? I have not been able to find a simple solution. Thanks. Skysnake

8. ## Sorting a 2D array by version

Hi, I have a 2D array with 2 columns, the 1st column contains a "version string" and the 2nd column contains a generic string. I want to sort it in the descending order so the latest version comes first. #include <Array.au3> Local \$aVersionsAndReleases[4][2] = [["0.2.8.9", "Release #1"], ["0.2.9.10", "Release #3"], ["0.2.9.11", "Release #4"], ["0.2.8.10", "Release #2"]] _ArraySort(\$aVersionsAndReleases, 1) ConsoleWrite(_ArrayToString(\$aVersionsAndReleases, ' - ')) _ArrayDisplay(\$aVersionsAndReleases) Unfortunately, _ArraySort isn't working here . This is the output generated by the script: 0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.9 - Release #1 0.2.8.10 - Release #2 The expected result should be: 0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.10 - Release #2 0.2.8.9 - Release #1 I am looking to develop an function which does this... but I don't know where to start . Can someone help me get started? Thanks in Advance! - TD.
9. ## Sort number GUICtrlCreateListView

Hello guys, I'm working with a simple script, complementing a GUICtrlCreateListView which has 5 columns. I would order the first column so that the numbers are decreasing. #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StructureConstants.au3> Opt('MustDeclareVars', 1) Global \$search_LV, \$B_DESCENDING GUICreate("ListView Sort by Column Click", 400, 300) \$search_LV = GUICtrlCreateListView("String|Number|String", 2, 2, 394, 268) GUICtrlSendMsg(\$search_LV, \$LVM_SETEXTENDEDLISTVIEWSTYLE, \$LVS_EX_GRIDLINES, \$LVS_EX_GRIDLINES) GUICtrlSendMsg(\$search_LV, \$LVM_SETEXTENDEDLISTVIEWSTYLE, \$LVS_EX_FULLROWSELECT, \$LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("line4|5|1A", \$search_LV) GUICtrlCreateListViewItem("line5|4.50 |1B", \$search_LV) GUICtrlCreateListViewItem("line10|4.0 |2C", \$search_LV) GUICtrlCreateListViewItem("line3|23|01", \$search_LV) GUICtrlCreateListViewItem("line2|0.34560 |09", \$search_LV) GUICtrlCreateListViewItem("line1|1.0 |7A", \$search_LV) GUICtrlCreateListViewItem("line1|0.1 |8C", \$search_LV) GUICtrlCreateListViewItem("line1|97|5B", \$search_LV) GUICtrlCreateListViewItem("line1|910|9B", \$search_LV) GUICtrlCreateListViewItem("line1|99|11", \$search_LV) GUICtrlCreateListViewItem("line1|990.99|06", \$search_LV) _GUICtrlListView_SetColumnWidth(\$search_LV, 0, 75) _GUICtrlListView_SetColumnWidth(\$search_LV, 1, 75) _GUICtrlListView_SetColumnWidth(\$search_LV, 2, 75) GUISetState() GUIRegisterMsg(\$WM_NOTIFY, "WM_NOTIFY") ;~ _GUICtrlListView_RegisterSortCallBack(\$search_LV, False) While 1 Switch GUIGetMsg() Case \$GUI_EVENT_CLOSE ExitLoop Case \$search_LV ; Kick off the sort callback ;~ _GUICtrlListView_SortItems(\$search_LV, GUICtrlGetState(\$search_LV)) ;~ _GUICtrlListView_UnRegisterSortCallBack(\$search_LV) EndSwitch WEnd Func WM_NOTIFY(\$hWnd, \$iMsg, \$iwParam, \$ilParam) #forceref \$hWnd, \$iMsg, \$iwParam Local \$hWndFrom, \$iIDFrom, \$iCode, \$tNMHDR, \$hWndListView, \$tInfo \$hWndListView = \$search_LV ;~ If Not IsHWnd(\$search_LV) Then \$hWndListView = GUICtrlGetHandle(\$search_LV) \$tNMHDR = DllStructCreate(\$tagNMHDR, \$ilParam) \$hWndFrom = HWnd(DllStructGetData(\$tNMHDR, "hWndFrom")) \$iIDFrom = DllStructGetData(\$tNMHDR, "IDFrom") \$iCode = DllStructGetData(\$tNMHDR, "Code") Switch \$hWndFrom ;~ Case \$search_LV Case GUICtrlGetHandle(\$search_LV) Switch \$iCode Case \$LVN_COLUMNCLICK ; A column was clicked ConsoleWrite("Header geklickt" & @CRLF) Local \$tInfo = DllStructCreate(\$tagNMLISTVIEW, \$iLparam) _GUICtrlListView_UnRegisterSortCallBack(\$search_LV) Local \$ColumnSorted = DllStructGetData(\$tInfo, 'SubItem') If \$ColumnSorted = 1 Then ConsoleWrite('Numeric: ' & _GUICtrlListView_RegisterSortCallBack(\$search_LV, True) & @CRLF) Else ConsoleWrite('Literal: ' & _GUICtrlListView_RegisterSortCallBack(\$search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems(\$search_LV, DllStructGetData(\$tInfo, 'SubItem')) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Ordering the "String" column, you notice that the line "line10" is not ordered last. And 'possible to order the "String" column in descending order? thank you very much
10. ## File list sort with default Windows enumeration

Hi guys, I wonder if there is a way to sort the filelist in an array from _FileListToArray () when files have the regular Windows enumeration example: File1 (1), File2 (2), File3 (3), etc. I'm posting two sample graphics so you can see what I mean I would like to get my list like in graphic 2 right now I'm getting my list like in graphic 1 which is the something I don't like. It's worth to say that I have no problem with a list when the files's names start with a number or is just a number thanks to the code found in this post. But, the problem is still present if I just get rid of the parenthesis that is () so in other words the problem happens when the enumeration is at the end of the names whether parenthesis are present or not.
11. ## excel sort,scheduling program

I want to coding a excel sort,scheduling system. When I input orgin file,and choose times(example is 7 times(A -->G)) system will output excel. (rule: 1 time include 1 Name ,but Food can't Repeat. secend's Food can't overlap with previous) How to codng of it ?!!!! Thank you veryvery much!!!!!! test.xlsx
12. ## _FileListToArray sorting ?

Hi I'am trying to list files from folder sorted by name (same as the picture) i tried this code #include <File.au3> \$arr = _FileListToArray("D:\2") _ArrayDisplay(\$arr) i am getting this result Any one could explain why it is putting 10-1 before 8-1 ? how can i make Autoit view file same as windows explorer ?
13. ## Excel Sort Method Attempt

Hi guys, I am using an old version of Excel.au3 which I am not ready to update yet so please help me. The old Excel.au3 does not have any method for SORT. I attempted to create one since i need one but I am getting an error. Here's my sample code: \$oAppl.Activesheet.UsedRange.sort(\$oAppl.Activesheet.cells(1,5),1,1) I thought this would work but I get the : ==> The requested action with this object has failed.: \$oAppl.Activesheet.UsedRange.sort(\$oAppl.Activesheet.cells(1,\$BidDayColNumber),1,1) \$oAppl.Activesheet.UsedRange.sort(\$oAppl.Activesheet.cells(1,\$BidDayColNumber),1,1)^ ERROR Any ideas or alternatives on sorting a range without calling from Excel.au3?

15. ## Listview sort column 0 (numbers) column 1 (strings)

Hi, just a short question. I 've got a lisitview with a few columns and I want to register a different sort for two kinds of columns. I 've got a solution, but I don't think it is a good one. Example : Col A = Names (Strings) Col B = Age (Integers) Right now I'm doing this: 1. _GUICtrlListView_RegisterSortCallBack 2. In my WM_NOTIFY Case GUICtrlGetHandle(\$search_LV) Switch \$iCode Case \$LVN_COLUMNCLICK ; A column was clicked Local \$tInfo = DllStructCreate(\$tagNMLISTVIEW, \$iLparam) ; Kick off the sort callback ;~ ConsoleWrite('SEARCH_LV Column geklickt' & @LF) ConsoleWrite("Sort: " & DllStructGetData(\$tInfo, 'SubItem')) If \$ColumnSorted <> DllStructGetData(\$tInfo, 'SubItem') Then _GUICtrlListView_UnRegisterSortCallBack(\$search_LV) ConsoleWrite('NEU' & @CRLF) EndIf \$ColumnSorted = DllStructGetData(\$tInfo, 'SubItem') If DllStructGetData(\$tInfo, 'SubItem') = 9 Or DllStructGetData(\$tInfo, 'SubItem') = 10 Then ConsoleWrite('True: ' & _GUICtrlListView_RegisterSortCallBack(\$search_LV, True) & @CRLF) Else ConsoleWrite('False ' & _GUICtrlListView_RegisterSortCallBack(\$search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems(\$search_LV, DllStructGetData(\$tInfo, 'SubItem')) So, I store the column clicked in a global variable. If the column is clicked again (sort asc or desc) then all is fine, if another column then the one before is clicked, I unregister the callback and create a new one. The new callback (in the if) depends on the column clicked because of the content to sort (strings or numbers). Is there an easier / better way? Do I have to use my own sorting function with GuiCtrlRegisterListViewSort? Edit: It still doesn't work in every case (just noticed). Thanks Mega
16. ## Sort Listview Name / Surname

I have a list view (first two colums are Name and Surname). Now I want to sort the items by alphabet. It should sort the names from A to Z and if the Name is teh shame it should sort it by the surname, too. I know about the _GUICtrlListView_SimpleSort() Function, but that only sorts one column. My problem is, that I want to save a value with the number in the list view (first is number one, second is number two...) in a file so when I need to retreive that value I search for the number of the item in the file. Thank you!
17. ## Annoying ListView thing ! (SOLVED!)

I recently managed to make a ListView sort correctly by clicking on it's columns, it does sort items very well but there's a very annoying thing >_< : every time after the items are sorted out, an item gets focused ! After I click a column, one item gets blue'd, like when its selected, even if its not ! Note that this happens only becuase of this function : _GUICtrlListView_SimpleSort Instead, the _GUICtrlListView_SortItems function is not doing this , but because of my luck,I must use _GUICtrlListView_SimpleSort ( but it is faster ) Here's my script to test to see what I mean: #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> \$Form1 = GUICreate("Form1", 383, 307, 192, 124) \$ListView1 = GUICtrlCreateListView("C1|C2|C3", 56, 16, 257, 241) GUICtrlSendMsg(-1, \$LVM_SETCOLUMNWIDTH, 0, 50) GUICtrlSendMsg(-1, \$LVM_SETCOLUMNWIDTH, 1, 50) GUICtrlSendMsg(-1, \$LVM_SETCOLUMNWIDTH, 2, 50) \$ListView1_0 = GUICtrlCreateListViewItem("1|5|6", \$ListView1) \$ListView1_1 = GUICtrlCreateListViewItem("2|7|8", \$ListView1) \$ListView1_2 = GUICtrlCreateListViewItem("3|9|10", \$ListView1) \$ListView1_3 = GUICtrlCreateListViewItem("4|11|12", \$ListView1) GUISetState(@SW_SHOW) Global \$toggle = 1 While 1 \$nMsg = GUIGetMsg() Switch \$nMsg Case \$GUI_EVENT_CLOSE Exit Case \$ListView1 _GUICtrlListView_SimpleSort(\$ListView1, \$toggle, GUICtrlGetState(\$ListView1)) EndSwitch WEnd How could I get rid of this item focus ?
18. ## ListView : When click to sort a column, instead sort other column?

How can I do to, when I click on on a specific column in a listview control, instead to get clicked/sorted other column. Is this possible ? I already know how to sort a column when I click on it : after the listview control was created, I add this code : _GUICtrlListView_RegisterSortCallBack(-1) I know that a gui can wait for a window event to happen, like a click on a control, but how can this be done to look if I clicked on a specific column and if so then, to sort (a clasic sort ) other column instead o.O ?
19. ## Sorting a ListView

I have a ListView that is created from a FileRead() using delimiters and then added into the ListView as shown below. Local \$src = InetGet(\$url, \$file, 1) \$data = FileRead(\$file) \$array = StringSplit(\$data, ";", 1) FileDelete(\$file) For \$n = 1 To UBound(\$array) - 1 Step 3 \$iItem = _GUICtrlListView_AddItem(\$ListView, \$array[\$n]) \$a = UBound(\$array) - 1 If \$n + 1 > \$a Then ExitLoop Else _GUICtrlListView_AddSubItem(\$ListView, \$iItem, \$array[\$n + 1], 1) _GUICtrlListView_AddSubItem(\$ListView, \$iItem, \$array[\$n + 2], 2) EndIf Next \$PlayerCount = _GUICtrlListView_GetItemCount(\$ListView) _GUICtrlListView_SetColumn(\$ListView, 0, "Name (Online: " & \$Count & ")") I was using _GUICtrlListView_SortItems to sort them and it appears to work correctly in that it adds the up and down arrow to the column but nothing moves. I tried another one that involved using DLL's but that didn't work either. Am I missing something or what?
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...