brodie28 Posted February 3, 2007 Posted February 3, 2007 I have an array set up like this Dim $targets[4][unknown] On the $targets[3][$i] in the array, a bunch of numbers are stored. I want to sort the array so that it gets sorted with those numbers going from smallest to biggest. I know it is done with _Arraysort, but I am not sure how to set it up so that it does what I want it to.
Moderators SmOke_N Posted February 3, 2007 Moderators Posted February 3, 2007 I have an array set up like this Dim $targets[4][unknown] On the $targets[3][$i] in the array, a bunch of numbers are stored. I want to sort the array so that it gets sorted with those numbers going from smallest to biggest. I know it is done with _Arraysort, but I am not sure how to set it up so that it does what I want it to.I've only ever done this with a 1 dim array, you can mod this if you like:Func _ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1) If $Ascending <> 0 And $Ascending <> 1 Then Return SetError(1) For $i = $Start To UBound($nArray) - 2 Local $SE = $i If $Ascending = 0 Then For $x = $i To UBound($nArray) - 1 If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x Next Else For $x = $i To UBound($nArray) - 1 If Number($nArray[$SE]) > Number($nArray[$x]) Then $SE = $x Next EndIf Local $HLD = $nArray[$i] $nArray[$i] = $nArray[$SE] $nArray[$SE] = $HLD Next EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
brodie28 Posted February 3, 2007 Author Posted February 3, 2007 Im sure _Arraysort can do it in one line though. I have done it before... But I forget how to set it up.
Moderators SmOke_N Posted February 3, 2007 Moderators Posted February 3, 2007 (edited) Im sure _Arraysort can do it in one line though.I have done it before... But I forget how to set it up.Unless they fixed it, I don't think it worked with numbers past 9 ...ie... 10 11If you had 12345678910and used _ArraySort() you got11023456789Which is why I made the _ArraySortNum() Edited February 3, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
brodie28 Posted February 3, 2007 Author Posted February 3, 2007 Ill possible come back and try to mod your code later on, its almost 6am here with no sleep : / Thus the looking for easy answers.
Developers Jos Posted February 3, 2007 Developers Posted February 3, 2007 Ill possible come back and try to mod your code later on, its almost 6am here with no sleep : /Thus the looking for easy answers.show some of your code so we can help.You can do it with the included _ArraySort() but need to remember to store the values as numbers not as string .. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
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