JPF 0 Posted March 27, 2011 (edited) Hi everybody,As you can probably tell i'm quite new to Autoit and seek your expertise and guidance!I have been given a challenge to read a set of numbers from a text file, have them sorted in descending order and write them to a seperate text file, or a message boxThe problem i'm having seems to be with the _Arraysort function, maybe?This is what I have tried so far.. dont laugh Dim $temp[5] =[FileRead("numero.txt")]_ArraySort($temp, 1)FileWrite("dupe.txt", $temp)Can anybody shed any light on this? It doesn't seem like enough but the help file hasn't been too kind to me eitherMuch appreciated! Edited March 27, 2011 by JPF Share this post Link to post Share on other sites
water 2,385 Posted March 27, 2011 (edited) #Include <File.au3> #include <array.au3> Global $aArray _FileReadToArray("numero.txt", $aArray) _ArraySort($aArray, 1, 1) _FileWriteFromArray("dupe.txt", $aArray, 1) Edited March 27, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
JPF 0 Posted March 27, 2011 #Include <File.au3> #include <array.au3> Global $aArray _FileReadToArray("numero.txt", $aArray) _ArraySort($aArray, 1, 1) _FileWriteFromArray("dupe.txt", $aArray, 1) Hi Water, thanks for the code! The only thing that happens there is the numbers that come back don't get sorted In the 'Numero' text file, I have simply typed = 1 2 8 4 9 What comes back into the 'Dupe' file is = 1 2 8 4 9 Any suggestions? Share this post Link to post Share on other sites
UEZ 1,272 Posted March 27, 2011 Try this: #include <Array.au3> $dest = "" $hFile = FileOpen("numero.txt") While True $line = FileReadLine($hFile) If @error = -1 Then ExitLoop $aNumbers = StringSplit($line, " ", 2) _ArraySort($aNumbers) $dest &= _ArrayToString($aNumbers, " ") & @CRLF WEnd FileClose($hFile) $hFile = FileOpen("Dupe.txt", 2) FileWrite($hFile, $dest) FileClose($hFile) Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Share this post Link to post Share on other sites
water 2,385 Posted March 27, 2011 What do you need to sort? The lines (rows) in the file or the numbers in each line? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
JPF 0 Posted March 27, 2011 What do you need to sort? The lines (rows) in the file or the numbers in each line?I need to sort the numbers in descending order The previous poster has sorted it, it does work now! (Many thanks!!) I just dont really understand the code very well... Water, if i add stringsplit to your code will that also work? Share this post Link to post Share on other sites
water 2,385 Posted March 27, 2011 Water, if i add stringsplit to your code will that also work?No, my code sorts lines, UEZ's code sorts the "words" in a line.In Excel: UEZ's code sorts the columns whereas my code sorts the lines. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
UEZ 1,272 Posted March 27, 2011 The question is how are the numbers saved in the text file? If the numbers are in each line then you have to read each line and sort it! If the numbers are in each row then you can use Water's code. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Share this post Link to post Share on other sites
JPF 0 Posted March 27, 2011 The question is how are the numbers saved in the text file?If the numbers are in each line then you have to read each line and sort it! If the numbers are in each row then you can use Water's code.Br,UEZGuys, totally understand it now! thats perfectThanks again! Understanding this has been abit of a mare :) Share this post Link to post Share on other sites