Valuater Posted February 17, 2006 Share Posted February 17, 2006 i want 10 to be #1 in the array. 10 8 6 4 2 instead i get 8 6 4 2 10 EXAMPLE #include <Array.au3> ; Example sort Array created with StringSplit. $avArray = StringSplit("6,8,10,4,2",",") _ArraySort( $avArray,1,1) ; sort and start at 1.. skip array[0] _ArrayDisplay( $avArray, "Sorted Desc starting at 1" ) thx 8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 17, 2006 Moderators Share Posted February 17, 2006 Here's a shot at it for ya Val:#include <Array.au3> ; Example sort Array created with StringSplit. $avArray = StringSplit("6,8,10,4,2,13,12,129,106",",") ArraySortNum($avArray) _ArrayDisplay( $avArray, "Sorted Desc starting at 1" ) Func ArraySortNum(ByRef $nArray, $Start = 1) For $i = $Start To UBound($nArray) - 2 Local $SE = $i For $x = $i To UBound($nArray) - 1 If Int($nArray[$SE]) < Int($nArray[$x]) Then $SE = $x Next 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. Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Author Share Posted February 17, 2006 Very Nice... Thanks SmOke_Ni was able to get away with this ( while you were working on it )For $j = 1 To $Lot - 1 If StringLen($LC[$j]) = 1 Then $LC[$j] = 0 & $LC[$j] $LC[$j] = $LC[$j] & "," & $L[$j]Next thanks again... and it works great!8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 17, 2006 Moderators Share Posted February 17, 2006 This is probably better, it handles decimals:#include <Array.au3> ; Example sort Array created with StringSplit. $avArray = StringSplit("6,8,10,4,2,13,12,129,106.3,106.4",",") ArraySortNum($avArray) _ArrayDisplay( $avArray, "Sorted Desc starting at 1" ) Func ArraySortNum(ByRef $nArray, $Start = 1) For $i = $Start To UBound($nArray) - 2 Local $SE = $i For $x = $i To UBound($nArray) - 1 If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x Next 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. Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Author Share Posted February 17, 2006 (edited) i will replace the post in "Autoit Wrappers" and.... i just realized that when the numbers do reach the 100's i will need to implement your UDF thx 8) Edited February 17, 2006 by Valuater Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 17, 2006 Moderators Share Posted February 17, 2006 Lmao... ok, last one I promise, for acending or decending:#include <Array.au3> ; Example sort Array created with StringSplit. $avArray = StringSplit("6,8,10,4,2,13,12,129,106.1,106.4",",") ArraySortNum($avArray, 0) _ArrayDisplay( $avArray, "Sorted Desc starting at 1" ) Func ArraySortNum(ByRef $nArray, $Decending = 1, $Start = 1) For $i = $Start To UBound($nArray) - 2 Local $SE = $i If $Decending = 1 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 EndFuncBack to work for me!! Cool, I made your list 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. Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Author Share Posted February 17, 2006 (edited) maybe change this?? ArraySortNum($avArray, 0) EDIT... not real important... 8) 8) Edited February 17, 2006 by Valuater Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 17, 2006 Moderators Share Posted February 17, 2006 (edited) Yeh, however you want... I don't know if I'd ever personally use it, but your right, $Decending I think should be $Decending = 0, that and If $Decendign = 0 Then, that way you could put 1 if you want to make acend, and nothing if you just want it to do decending. Edit: Yeh that looks better IMHO:#include <Array.au3> ; Example sort Array created with StringSplit. $avArray = StringSplit("6,8,10,4,2,13,12,129,106.1,106.4",",") ArraySortNum($avArray, 1) _ArrayDisplay( $avArray, "Sorted Desc starting at 1" ) Func ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 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 Edited February 17, 2006 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. Link to comment Share on other sites More sharing options...
herewasplato Posted February 17, 2006 Share Posted February 17, 2006 i want 10 to be #1 in the array.Rolling StonesYou can't always get what you wantYou can't always get what you wantYou can't always get what you wantBut if you try sometimes well you just might findYou get what you needSmOke_N thought that you needed that UDF :-)Maybe we should adopt that for Newbies...if you try (post some code)...we might give you what you need [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Author Share Posted February 17, 2006 Rolling StonesSmOke_N thought that you needed that UDF :-)Maybe we should adopt that for Newbies...if you try (post some code)...we might give you what you needSmOke_N really tried and it is appreciatedi did want it......and i got what i needed...i think that would be a great idea for ALL Newbies8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 17, 2006 Moderators Share Posted February 17, 2006 Rolling StonesSmOke_N thought that you needed that UDF :-)Maybe we should adopt that for Newbies...if you try (post some code)...we might give you what you needHmm, Did I do something wrong, or am I just not understanding this? Didn't you want the highest value number to the lowest value number? I assumed this because of using _arraysort()... or maybe I'm just not understanding what plato's saying here. 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. Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Author Share Posted February 17, 2006 No... you didn't do anything wrong he was saying maybe if Newbies would try by posting some script and telling us what they want.... we might be able to help them and give them what they need 8) Link to comment Share on other sites More sharing options...
herewasplato Posted February 17, 2006 Share Posted February 17, 2006 ...or maybe I'm just not understanding what plato's saying here.I thought that this might happen when I tried to work you and your posts/code into that joke...I thought of that song as soon as I saw "want" in the first post - before there were any replies. I went off to look at the Array UDF to see if I could help (like I had a chance at understandin' that code). Once I saw that the solution was in your capable hands, I just waited for a chance to inject the jest.I was tryin' to say that you gave Val what exactly what he needed (and coded well to boot).In keeping with the Newbie jest, it is Val that should have tried (more than the mere 3 lines that showed the problem - where is the attempt at the solution in the first post Val?) Of course, if we had all just ignored Val, he would have posted the answer to his own question soon enough. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Author Share Posted February 17, 2006 (edited) Wow... guess i was wrong I would never ask without trying many times to get what i am after these are true in a message box 01 + 1 = 2 01 + 01 = 2 I was in the middle of 3 for/next loops cheking a stringsplit... I actually thought that maybe one of the base/ubounds/index/ or whatever might do the trick and someone might know what to put in this line _ArraySort ( ByRef $a_Array, [$i_Descending[, $i_Base=0[, $i_Ubound=0[, $i_Dim=1[, $i_SortIndex=0]]]]] ) i think i got lucky in one of the last lines i was able to do the test If StringLen($LC[$j]) = 1 Then $LC[$j] = 0 & $LC[$j] ... again another for/next loop yes... i always try.. i just dont always put my non-working code in 8) Edited February 17, 2006 by Valuater Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 17, 2006 Moderators Share Posted February 17, 2006 I thought that this might happen when I tried to work you and your posts/code into that joke...I thought of that song as soon as I saw "want" in the first post - before there were any replies. I went off to look at the Array UDF to see if I could help (like I had a chance at understandin' that code). Once I saw that the solution was in your capable hands, I just waited for a chance to inject the jest.I was tryin' to say that you gave Val what exactly what he needed (and coded well to boot).In keeping with the Newbie jest, it is Val that should have tried (more than the mere 3 lines that showed the problem - where is the attempt at the solution in the first post Val?) Of course, if we had all just ignored Val, he would have posted the answer to his own question soon enough. I get it... Actually, the idea that Val even asked for help as much as he gives (as do you), I would have spent a couple of hours trying to figure out a solution for it if needed, but it just so happens that I was working on something similar last week. Although his code was short indeed, the UDF he was using told me specifically what he was trying to do (so I thought until I didn't understand the jesting ).Although it was only a few lines, it was interpretable for me... unlike a "I want to make a "Program" to read my girlfriends messenger, and upload a file to my ftp server when she has decided to stop talking... can someone help?Thanks (Actually that description is better than most! ) God those post piss me off! First off to use the word "I", then not provide anything that "I" has done is so condescending!! Then have the audacity after someone posts something (although I don't think they should) to say "No, that's not what I want to do"! 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. Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Author Share Posted February 17, 2006 Then have the audacity after someone posts something ... to say "No, that's not what I want to do"! sick.gifdido!!8) Link to comment Share on other sites More sharing options...
herewasplato Posted February 17, 2006 Share Posted February 17, 2006 Wow... guess i was wrong...no no no... I'm just too tired to convey humor tonight. I assumed that he took this "SmOke_N really tried and it is appreciated" combined with my joke to mean that he tried and failed. So I went for - it was you that should have tried. :-) ...but alas, your first post was great - it showed the problem in just enough code - and since you did try in your first post, I had to reach for "no attempted solution code" to make my analogy work. [You just don't make a good Newbie!] My, "where is the attempt at the solution in the first post Val?" should have been followed by many smilies! [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
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