WeMartiansAreFriendly Posted May 17, 2007 Share Posted May 17, 2007 (edited) Ok, This might not make any sence, but I need to sort a 2D array, The first dimension will be sorted like normal and the second dimension will mirror how the first dimension was sorted e.g. the index number changes, but the second dimension cannot be sorted by contents, I need them to be in sync with eachother. thanks heres basically what i was trying to do, i dont want it to sort the second one because it screws up everything because of the blank lines it doesn't have to be 2D, i'd be happy if was 1D. too #include <array.au3> Dim $arTest[10][2] $arTest[0][0] = 'Hi' $arTest[1][0] = 'Hello' $arTest[2][0] = 'Howdy' $arTest[3][0] = 'How''s it going?' $arTest[4][0] = 'How''s the weather?' $arTest[5][0] = 'What''s up' $arTest[6][0] = 'How are you' $arTest[7][0] = 'Hi there' $arTest[8][0] = 'Yo' $arTest[9][0] = 'Top-o the mornin''n to you' $arTest[0][1] = 'Goodbye' $arTest[1][1] = 'Later' $arTest[2][1] = '' $arTest[3][1] = 'Good riddence' $arTest[4][1] = '' $arTest[5][1] = 'See ya' $arTest[6][1] = 'Bye Bye $arTest[7][1] = '' $arTest[8][1] = '' $arTest[9][1] = '' _ArrayDisplay2D($arTest, "unsorted") _ArraySort_2ary($arTest) _ArrayDisplay2D($arTest, "sorted - both dimensions") oÝ÷ ÚÚºÚ"µÍÚ[ÛYH Ø^K]LÉÝÂ[H ÌÍØÝVÌLK ÌÍØÝÌLBÌÍØÝVÌHH ÌÎNÒIÌÎNÂÌÍØÝVÌWHH ÌÎNÒ[ÉÌÎNÂÌÍØÝVÌHH ÌÎNÒÝÙIÌÎNÂÌÍØÝVÌ×HH ÌÎNÒÝÉÌÎNÉÌÎNÜÈ]ÛÚ[ÏÉÌÎNÂÌÍØÝVÍHH ÌÎNÒÝÉÌÎNÉÌÎNÜÈHÙX]ÉÌÎNÂÌÍØÝVÍWHH ÌÎNÕÚ] ÌÎNÉÌÎNÜÈ ÌÎNÂÌÍØÝVÍHH ÌÎNÒÝÈH[ÝIÌÎNÂÌÍØÝVÍ×HH ÌÎNÒHIÌÎNÂÌÍØÝVÎHH ÌÎNÖ[ÉÌÎNÂÌÍØÝVÎWHH ÌÎNÕÜ[ÈH[Ü[ÌÎNÉÌÎNÛÈ[ÝIÌÎNÂÌÍØÝÌHH ÌÎNÑÛÛÙYIÌÎNÂÌÍØÝÌWHH ÌÎNÓ]ÌÎNÂÌÍØÝÌHH ÌÎNÉÌÎNÂÌÍØÝÌ×HH ÌÎNÑÛÛÙY[ÙIÌÎNÂÌÍØÝÍHH ÌÎNÉÌÎNÂÌÍØÝÍWHH ÌÎNÔÙYHXIÌÎNÂÌÍØÝÍHH ÌÎNÐYHYIÌÎNÂÌÍØÝÍ×HH ÌÎNÉÌÎNÂÌÍØÝÎHH ÌÎNÉÌÎNÂÌÍØÝÎWHH ÌÎNÉÌÎNÂÐ^QÜ^J ÌÍØÝK ][ÝÝ[ÛÜY ][ÝÊBÐ^TÛÜ ÌÍØÝJBÐ^QÜ^J ÌÍØÝK ][ÝÜÛÜY ][ÝÊB Edited May 17, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Developers Jos Posted May 17, 2007 Developers Share Posted May 17, 2007 (edited) Ok, This might not make any sence, but I need to sort a 2D array, The first dimension will be sorted like normal and the second dimension will mirror how the first dimension was sorted e.g. the index number changes, but the second dimension cannot be sorted by contents, I need them to be in sync with eachother. thanksheres basically what i was trying to do, i dont want it to sort the second one because it screws up everything because of the blank lines it doesn't have to be 2D, i'd be happy if was 1D. tooMaybe I am not understanding it but what is wrong with the 2 separate Arrays ?Or do you want :_ArrayDisplay($arTest, "unsorted")_ArraySort($arTest,0,0,0,2)_ArrayDisplay($arTest, "unsorted") Edited May 17, 2007 by JdeB 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. Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted May 17, 2007 Author Share Posted May 17, 2007 (edited) Okay, my english is not the best... maybe this may help you help me a little bit more I need them to be sorted but also in sync with eachother.. #include <array.au3> Dim $str Dim $arTest1[10] = ['1+1','5+10','blank','Whats the color of the sky','blank','5+5','0', _ 'blank is','blank','ABCD?'] Dim $arTest2[10] = ['2','15','','Blue','','10','0','','','EFGH..'] ;notice how they are in sync with eachother, but out of alphabetical order for $x = 0 To 9 $str &= $arTest1[$x] &' = '& $arTest2[$x] & @CRLF Next MsgBox(0,'Unsorted',$str) _ArraySort($arTest1) _ArraySort($arTest2) $str = '' ;Now they are sorted but out of sync with eachother. for $x = 0 To 9 $str &= $arTest1[$x] &' = '& $arTest2[$x] & @CRLF Next MsgBox(0,'Sorted',$str) Edited May 17, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Developers Jos Posted May 17, 2007 Developers Share Posted May 17, 2007 Okay, my english is not the best... maybe this may help you help me a little bit more I need them to be sorted but also in sync with eachother..Did you see my EDIT on the previous post ? 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. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 17, 2007 Share Posted May 17, 2007 (edited) What the heck is up with _ArraySort() from array.au3? I thought a 2D array made more sense for this topic, so I coded it as a demo: #include <array.au3> Dim $avTest1[5] = ['1+1', '5+10', 'blank', 'Whats the color of the sky', 'blank'] Dim $avTest2[5] = ['2', '15', '', 'Blue', ''] Dim $avTest[UBound($avTest1)][2] For $a = 0 To UBound($avTest) - 1 $avTest[$a][0] = $avTest1[$a] $avTest[$a][1] = $avTest2[$a] Next _ArrayDisplay2D($avTest, "Before") _ArraySort($avTest, 0, 0, 0, 2) ; <--- tweaked per JdeB _ArrayDisplay2D($avTest, "After") Func _ArrayDisplay2D($avInput, $sTitle = "") Local $x, $y, $sResult = "" For $x = 0 To UBound($avInput, 1) - 1 For $y = 0 To UBound($avInput, 2) - 1 $sResult &= "[" & $x & "][" & $y & "] = " & $avInput[$x][$y] & @CRLF Next $sResult &= @CRLF Next MsgBox(0, $sTitle, $sResult) EndFunc ;==>_ArrayDisplay2D But it gets an error and fails on the _ArraySort(): C:\PROGRA~1\AutoIt3\Include\array.au3 (664) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $t = $array[$i] $t = ^ ERROR ->15:55:48 AutoIT3.exe ended.rc:1 The help files for the 3.2.3 series of betas and the various 3.2.4 prods recently (last try was with 3.2.4.4) ALL say: Remarks This sort functions can handle 1 or 2 dimension arrays. Waah! Whine, moan, groan, whimper, complain, etc... Edit: OK, JdeB's tweak to the _ArraySort() parameters fixed it. But the whining remains, because that is a completely unnecessary parameter. The function should be able to figure that out with Ubound($avInput, 0) and then Ubound($avInput, 2). Phhhhbbbbbsst! Edited May 17, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted May 17, 2007 Author Share Posted May 17, 2007 Did you see my EDIT on the previous post ?thanks.. but the example in the second post should better reflect what I was needing.. I hope. :S Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted May 17, 2007 Author Share Posted May 17, 2007 (edited) What the heck is up with _ArraySort() from array.au3? I thought a 2D array made more sense for this topic, so I coded it as a demo: ... The help files for the 3.2.3 series of betas and the various 3.2.4 prods recently (last try was with 3.2.4.4) ALL say: Waah! Whine, moan, groan, whimper, complain, etc... hmm.. thats no fun. Edited May 17, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Developers Jos Posted May 17, 2007 Developers Share Posted May 17, 2007 Edit: OK, JdeB's tweak to the _ArraySort() parameters fixed it. But the whining remains, because that is a completely unnecessary parameter. The function should be able to figure that out with Ubound($avInput, 0) and then Ubound($avInput, 2).Phhhhbbbbbsst! True, BUT:As always there is a history for this... once upon a time , a long time ago, the Ubound() command wasn't capable of determining the number of dimension, thus it had to be specified.Now how to change trhis without breaking many scripts? 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. Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted May 17, 2007 Author Share Posted May 17, 2007 thanks for the help.. couldn't figure out by myself Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Gigglestick Posted May 17, 2007 Share Posted May 17, 2007 So umm.... to clarify... what you want to do is sort the first array, moving the second array's parts around exactly the same, right? So if the indexes of the first array 1,2,3,4,5 end up as 1,4,2,3,5 after, you want the second array's indexes 1,2,3,4,5 to be reordered to 1,4,2,3,5 to match the first array. My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 17, 2007 Share Posted May 17, 2007 So umm.... to clarify... what you want to do is sort the first array, moving the second array's parts around exactly the same, right?So if the indexes of the first array 1,2,3,4,5 end up as 1,4,2,3,5 after, you want the second array's indexes 1,2,3,4,5 to be reordered to 1,4,2,3,5 to match the first array....which is done automatically if you just assemble them into a 2D array first. That's what lead me to the demo script in post #5. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 17, 2007 Share Posted May 17, 2007 (edited) True, BUT: As always there is a history for this... once upon a time , a long time ago, the Ubound() command wasn't capable of determining the number of dimension, thus it had to be specified. Now how to change trhis without breaking many scripts? I see what you mean. But if the updated _ArraySort() UDF just ignores that parameter, and uses Ubound() internally instead, that wouldn't break anything in legacy scripts would it? An then that sort of a 2D array would have worked as just: _ArraySort($arTest)oÝ÷ Øpy©vl®¶²+)¬¶)í¡©À®¶²+)¬·Ú,0«H槵«¢+Ø¥¹±Õ±ÐíÉÉä¹ÔÌÐì()¥´ÀÌØíÙQÍÐÅlÕtôlÌäìĬÄÌäì°ÌäìÄÀ´ÔÌäì°Ìäí±¹¬Ìäì°Ìäí]¡ÑÌÑ¡½±½È½Ñ¡ÍäÌäì°Ìäí±¹¬Ìäít)¥´ÀÌØíÙQÍÐÅMÕlÄÁtôlÌäíµÑ Ìäì°Ìäí¥Ñ¥½¸Ìäì°ÌäíµÑ Ìäì°ÌäíÍÕÑÉÑ¥½¸Ìäì°Ìäí9Ìäì°Ìäí9Ìäì°ÌäíÅÕ¥èÌäì°Ìäí½±½ÉÌÌäì°Ìäí9Ìäì°Ìäí9Ìäít)¥´ÀÌØíÙQÍÐÉlÕtôlÌäìÈÌäì°ÌäìÔÌäì°ÌäìÌäì°Ìäí ±ÕÌäì°ÌäìÌäít)¥´ÀÌØíÙQÍÐÉMÕlÄÁtôlÌäí¹ÕµÈÌäì°ÌäíÙ¸Ìäì°Ìäí¹ÕµÈÌäì°Ìäí½Ìäì°Ìäí9Ìäì°Ìäí9Ìäì°ÌäíݽÉÌäì°Ìäí½±½ÈÌäì°Ìäí9Ìäì°Ìäí9Ìäít()¥´ÀÌØíÙQÍÑmU ½Õ¹ ÀÌØíÙQÍÐĤulÉulÍt)½ÈÀÌØíôÀQ¼U ½Õ¹ ÀÌØíÙQÍФ´Ä($ìÅÕÍÑ¥½¸¹¥ÐÌäíÌÁɽÁÉÑ¥Ì($ÀÌØíÙQÍÑlÀÌØíulÁulÁtôÀÌØíÙQÍÐÅlÀÌØít($ÀÌØíÙQÍÑlÀÌØíulÁulÅtôÀÌØíÙQÍÐÅMÕlÀÌØí¨Ét($ÀÌØíÙQÍÑlÀÌØíulÁulÉtôÀÌØíÙQÍÐÅMÕl ÀÌØí¨È¤¬Åt($ì¹ÍÝȹ¥ÐÌäíÌÁɽÁÉÑ¥Ì($ÀÌØíÙQÍÑlÀÌØíulÅulÁtôÀÌØíÙQÍÐÉlÀÌØít($ÀÌØíÙQÍÑlÀÌØíulÅulÅtôÀÌØíÙQÍÐÉMÕlÀÌØí¨Ét($ÀÌØíÙQÍÑlÀÌØíulÅulÉtôÀÌØíÙQÍÐÉMÕl ÀÌØí¨È¤¬Åt)9áÐ()%5Í ½à ÌȬаÅÕ½Ðí}ÉÉå¥ÍÁ±äÍ ¤µ¼ÅÕ½Ðì°ÅÕ½Ðí¼å½ÔݹÐѼÍÑ¡¥±½½àüÅÕ½Ðì¤ôØQ¡¸(%}ÉÉå¥ÍÁ±äÍ ÀÌØíÙQÍаÅÕ½ÐíIÍÕ±ÑÌÅÕ½Ðì¤)±Í($ÀÌØí¥±ôQµÁ¥ÈµÀìÅÕ½ÐìÀäÈí}ÉÉå¥ÍÁ±ä͹ÑáÐÅÕ½Ðì($ÀÌØí¡¥±ô¥±=Á¸ ÀÌØí¥±°È¤(%¥±]É¥Ñ ÀÌØí¡¥±°}ÉÉå¥ÍÁ±äÍ ÀÌØíÙQÍаÅÕ½ÐìÅÕ½Ðì°Ä¤¤(%¥± ±½Í ÀÌØí¡¥±¤(%IÕ¸ Ìäí¹½ÑÁ¹áÅÕ½ÐìÌäìµÀìÀÌØí¥±µÀìÌäìÅÕ½ÐìÌäì¤)¹%((ì´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´(ìչѥ½¸}ÉÉå¥ÍÁ±äÍ ¤(ì%IÑÕɹÌÑ¡½ÉµÑѽ¹Ñ¹Ñ̽Űɰ½ÈÍÉÉä̵ձѥ±¥¹ÍÑÉ¥¹°(ì$%¹¥ÀÌØí±ôÀ¡Õ±Ð¤¥ÍÁ±åÌÑ¡ÍÑÉ¥¹¥¸¥±½½à¸(ì% ±°Ý¥Ñ è}ÉÉå¥ÍÁ±äÍ¡ åIÀÌØíÙÉÉäl°ÀÌØíÍQ¥Ñ±l°ÀÌØí±ut¤(ì$%Ý¡Éè$ÀÌØíÙÉÉä¥ÌÑ¡ÉÉäѼ¥ÍÁ±å¡Ý¥±°¹½Ðµ½¥¥¤(ì$$$$ÀÌØíÍQ¥Ñ±¥Ìѥѱ½ÈÑ¡¥±½½à°Õ±Ð¥ÌÅÕ½ÐìÅÕ½Ðì(ì$$$$ÀÌØí±ô$À¡Õ±Ð¤ÉÑÕɸÍÑÉ¥¹¹¥ÍÁ±ä¥±½½à(ì$$$$$$ÄÍÕÁÉÍÍÌ¥ÍÁ±å¥¹¥±½½à°½¹±äÉÑÕɹÌÍÑÉ¥¹(ì%=¸ÍÕÍÌÉÑÕɹÌÍÑÉ¥¹½½ÉµÑÑÉÉ佹ѹÑ̸(ì%=¸¥±ÕÉ°ÉÑÕɹÌÀ¹ÍÑÌÉɽÈ(ì´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´)Õ¹}ÉÉå¥ÍÁ±äÍ¡ åIÀÌØíÙ%¹ÁÕаÀÌØíÍQ¥Ñ±ôÅÕ½ÐìÅÕ½Ðì°ÀÌØí±ôÀ¤(%1½°ÀÌØíà°ÀÌØíä°ÀÌØíè°ÀÌØíÍIÍÕ±ÐôÅÕ½ÐìÅÕ½Ðì(%%9½Ð%ÍÉÉä ÀÌØíÙ%¹ÁÕФQ¡¸IÑÕɸMÑÉÉ½È Ä°À°À¤($(%1½°ÀÌØí¥µÌôU ½Õ¹ ÀÌØíÙ%¹ÁÕаÀ¤(%%ÀÌØí¥µÌÐìÌQ¡¸IÑÕɸMÑÉÉ½È È°À°À¤($(%MÝ¥Ñ ÀÌØí¥µÌ($% ÍÄ($$%½ÈÀÌØíàôÀQ¼U ½Õ¹ ÀÌØíÙ%¹ÁÕаĤ´Ä($$$$ÀÌØíÍIÍձеÀìôÅÕ½ÐílÅÕ½ÐìµÀìÀÌØíàµÀìÅÕ½ÐítôÅÕ½ÐìµÀìÀÌØíÙ%¹ÁÕÑlÅtµÀì I1($$%9áÐ($% ÍÈ($$%½ÈÀÌØíàôÀQ¼U ½Õ¹ ÀÌØíÙ%¹ÁÕаĤ´Ä($$$%½ÈÀÌØíäôÀQ¼U ½Õ¹ ÀÌØíÙ%¹ÁÕаȤ´Ä($$$$$ÀÌØíÍIÍձеÀìôÅÕ½ÐílÅÕ½ÐìµÀìÀÌØíàµÀìÅÕ½ÐíulÅÕ½ÐìµÀìÀÌØíäµÀìÅÕ½ÐítôÅÕ½ÐìµÀìÀÌØíÙ%¹ÁÕÑlÀÌØíáulÀÌØíåtµÀì I1($$$%9áÐ($$$$ÀÌØíÍIÍձеÀìô I1($$%9áÐ($% ÍÌ($$%½ÈÀÌØíàôÀQ¼U ½Õ¹ ÀÌØíÙ%¹ÁÕаĤ´Ä($$$%½ÈÀÌØíäôÀQ¼U ½Õ¹ ÀÌØíÙ%¹ÁÕаȤ´Ä($$$$%½ÈÀÌØíèôÀQ¼U ½Õ¹ ÀÌØíÙ%¹ÁÕа̤´Ä($$$$$$ÀÌØíÍIÍձеÀìôÅÕ½ÐílÅÕ½ÐìµÀìÀÌØíàµÀìÅÕ½ÐíulÅÕ½ÐìµÀìÀÌØíäµÀìÅÕ½ÐíulÅÕ½ÐìµÀìÀÌØíèµÀìÅÕ½ÐítôÅÕ½ÐìµÀìÀÌØíÙ%¹ÁÕÑlÀÌØíáulÀÌØíåulÀÌØíétµÀì I1($$$$%9áÐ($$$%9áÐ($$$$ÀÌØíÍIÍձеÀìô I1($$%9áÐ(%¹MÝ¥Ñ (%%9½ÐÀÌØí±Q¡¸5Í ½à À°ÀÌØíÍQ¥Ñ±°ÀÌØíÍIÍձФ(%IÑÕɸÀÌØíÍIÍÕ±Ð)¹Õ¹ìôôÐí}ÉÉå¥ÍÁ±äÍ Edit: Tweaked demo to show suppression of dialog box (string only). Edited May 17, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Developers Jos Posted May 17, 2007 Developers Share Posted May 17, 2007 I see what you mean. But if the updated _ArraySort() UDF just ignores that parameter, and uses Ubound() internally instead, that wouldn't break anything in legacy scripts would it? An then that sort of a 2D array would have worked as just: _ArraySort($arTest) I know and been planning to do so ... its just something i need to get done... 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. 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