Nhato Posted July 30, 2015 Posted July 30, 2015 Hello, sorry to bother you, i cannot find the mistake.i have a .txt file containing:407 772 613 363 775 Ultimate 840 1242 3520 1244 and i want to sort it with.#Include <Array.au3> #Include <File.au3> Local $sort _FileReadToArray(@workingdir & "\list.txt",$sort) _ArrayDisplay($sort) _ArraySort($sort,1,1) _ArrayDisplay($sort) but the result is this:[0]|10 [1]|Ultimate [2]|840 [3]|775 [4]|772 [5]|613 [6]|407 [7]|363 [8]|3520 [9]|1244 [10]|1242i like that "Ultimate" is on top, but WHY are the 4 digit numbers at the bottom?thanks for helping
jguinch Posted July 30, 2015 Posted July 30, 2015 #Include <Array.au3> Local $aList[10] = ["407", "772", "613", "363", "775", "Ultimate", "840", "1242", "3520", "1244"] _ArrayDisplay($aList) _ArraySort($aList, 1,1 ) _ArrayDisplay($aList)The result is good : order descending by alphebitical order Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
guinness Posted July 30, 2015 Posted July 30, 2015 Don't forget you can do this in AuoIt v3.3.10.0+Local $aList = ["407", "772", "613", "363", "775", "Ultimate", "840", "1242", "3520", "1244"] UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Nhato Posted July 30, 2015 Author Posted July 30, 2015 thanks for your help!i also noticed that autoit sorts good when setting the array in the script, but i need to combine this with a text file that could grow very large. any ideas?
guinness Posted July 30, 2015 Posted July 30, 2015 Use a database, look at the SQLite functions. Having a flat file that grows exponentially over time is just going to cause more headaches than it's really worth. If you don't understand databases, then now is a good time as any to learn. Read this to see how to think in terms of tables etc..https://www.autoitscript.com/forum/topic/173843-databases-arent-scary-see-why-in-this-short-demo/ UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Malkey Posted July 31, 2015 Posted July 31, 2015 ....but the result is this:[0]|10 [1]|Ultimate [2]|840 [3]|775 [4]|772 [5]|613 [6]|407 [7]|363 [8]|3520 [9]|1244 [10]|1242i like that "Ultimate" is on top, but WHY are the 4 digit numbers at the bottom?thanks for helpingThat array sort above is correct - even though it's from a file. The array count,10, is in the first element, put there by the _FileReadToArray function.The 4 digit numbers at the bottom are treated as strings. And are at the bottom because :-3520 is less than 365 alphabetically sorted,1244 is less than 3520 alphabetically sorted, and,1242 is less than 1244 alphabetically sorted.Here is an example of sorting an array numerically.#include <Array.au3> #include <File.au3> Local $sort, $Temp, $Loop = 1 Local $Dec = 0 ; $Dec = 1 sort descending; $Dec = 0 sort ascending _FileReadToArray("list.txt", $sort) ; $FRTA_COUNT (1) - array count in the first element. (default) _ArrayDisplay($sort) While $Loop ; Keep looping until If statement is missed. $Loop = 0 For $i = 2 To UBound($sort) - 1 If (Number($sort[$i]) > Number($sort[$i - 1]) And $Dec = 1) Or _ ; Sort Descending (Number($sort[$i]) < Number($sort[$i - 1]) And $Dec = 0) Then ; Sort Ascending ; ---- Swap $sort[$i] with $sort[$i - 1] ---- $Temp = $sort[$i] $sort[$i] = $sort[$i - 1] $sort[$i - 1] = $Temp ; ------------------------------------------- $Loop = 1 ; Keep looping EndIf Next WEnd _ArrayDisplay($sort) jvds 1
Skysnake Posted August 12, 2015 Posted August 12, 2015 Ah, help please?I used this data:Local $aList = ["407", "772", "613", "363", "775", "Ultimate", "840", "1242", "3520", "1244"]using the sort function above, and got this result:407 Ultimate 363 613 772 775 840 1242 1244 3520Forgive my confusion, but wasnt this supposed to show a number sort? ie I would expect "Ultimate" at the top, followed by all the numeric values, starting at 363, 407, 613... -> why does it (a) not place the text at the top (or bottom) and why are the numbers not in order? Probably the same answer, but it is beyond me. Thank you for your kind assistance. Skysnake Why is the snake in the sky?
Malkey Posted August 13, 2015 Posted August 13, 2015 SkysnakeNote that your sort does not include the first element in the sort.The example sort of post #6, sorts the array from FileReadToArray function, which puts the number of elements of the array in the first element.To allow the inclusion of the first element in the sort, change the line in the script of post #6 fromFor $i = 2 To UBound($sort) - 1to For $i = 1 To UBound($sort) - 1
Skysnake Posted August 13, 2015 Posted August 13, 2015 my bad sorted, thanks, works as expected Skysnake Why is the snake in the sky?
UEZ Posted August 13, 2015 Posted August 13, 2015 You can use the Natural Order String Comparison by wraithdu.#include "_ArrayNaturalSort.au3" Local $aList[10] = ["407", "772", "613", "363", "775", "Ultimate", "840", "1242", "3520", "1244"] _ArrayNaturalSort($aList) _ArrayDisplay($aList) Result:Row|Col 0 [0]|363 [1]|407 [2]|613 [3]|772 [4]|775 [5]|840 [6]|1242 [7]|1244 [8]|3520 [9]|Ultimate 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Skysnake Posted August 13, 2015 Posted August 13, 2015 thanks for the reference. this has been a common question elsewhere on 'why does my x not sort like i expect' thanks, works well Skysnake Why is the snake in the sky?
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