JPF Posted March 27, 2011 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
water Posted March 27, 2011 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
JPF Posted March 27, 2011 Author 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?
UEZ Posted March 27, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
water Posted March 27, 2011 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
JPF Posted March 27, 2011 Author 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?
water Posted March 27, 2011 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
UEZ Posted March 27, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
JPF Posted March 27, 2011 Author 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 :)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now