BlazerV60 Posted June 21, 2014 Posted June 21, 2014 Hello everyone, I created this small script that shows a list of 10 people in an array. Each person is associated with a number which is stored in another array. Chris is associated with 3, Brian with 4, Daniel with 2, Stephen with 6 and so on. I then made the first array (with the names in them), to be sorted in alphabetical order. How can I make the second array with the numbers in them, also sorted accordingly so that each person is still matched with their number? #include <Array.au3> #include <File.au3> Local $Array1[10] = ["Chris","Brian","Daniel","Stephen","William", "Joseph", "Diana", "Thomas", "Jason", "Carol"] Local $Array2[10] = [3, 4, 2, 6, 7, 1, 9, 10, 5, 8] _ArraySort($Array1) _ArrayDisplay($Array1, "Sorted in Alphabetical Order") ;Display Array2 showing the new sorted out rows, so that each person is still matched with the number they are associated with. Results should show 4, 8, 3, 2, 9, 5, 1, 6, 10, 7 Thanks, Brian
UEZ Posted June 21, 2014 Posted June 21, 2014 Use a 2d array instead of 2x 1d arrays. Br, UEZ BlazerV60 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
jchd Posted June 22, 2014 Posted June 22, 2014 Like UEZ said, like this: #include <Array.au3> Local $Array1 = [ _ ["Chris", 3], _ ["Brian", 4], _ ["Daniel", 2], _ ["Stephen", 6], _ ["William", 7], _ ["Joseph", 1], _ ["Diana", 9], _ ["Thomas", 10], _ ["Jason", 5], _ ["Carol", 8] _ ] _ArraySort($Array1) _ArrayDisplay($Array1, "Sorted in Alphabetical Order") BlazerV60 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
BlazerV60 Posted June 22, 2014 Author Posted June 22, 2014 Thanks UEZ and jchd! That made sense and I was able to get the results I wanted thanks to the 2d array method. I have one more question though, jchd, you had to manually type out both of my columns in your code. Is there a way to combine both of my original 1d arrays into a 2d array with 2 columns through some sort of autoit code? Because my arrays may have 1000 entries in each and it would take too long to manually type those out. Thanks, Brian
Solution jchd Posted June 22, 2014 Solution Posted June 22, 2014 Of course there is the simple pedestrian way: use a For..Next loop with a single index used to read $Partial1DArray1, $Partial1DArray2 and write $Monster2DArray elements. #include <Array.au3> Local $Array1 = ["Chris","Brian","Daniel","Stephen","William", "Joseph", "Diana", "Thomas", "Jason", "Carol"] Local $Array2 = [3, 4, 2, 6, 7, 1, 9, 10, 5, 8] If UBound($Array1) <> UBound($Array2) Then MsgBox(0, "", "Big mistake") Else Local $Array[UBound($Array1)][2] For $i = 0 To UBound($Array1) - 1 $Array[$i][0] = $Array1[$i] $Array[$i][1] = $Array2[$i] Next ; optionally free both partial arrays $Array1 = 0 $Array2 = 0 _ArraySort($Array) _ArrayDisplay($Array, "Sorted in Alphabetical Order") EndIf BlazerV60 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
BlazerV60 Posted June 22, 2014 Author Posted June 22, 2014 And with that, all my problems are solved. Thanks jchd
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