Popular Post jguinch Posted January 8, 2016 Popular Post Share Posted January 8, 2016 (edited) Hello all ! Here are some functions that I have created to manipulate multidimensionnal arrays. I think some of them can be useful. Some functions are limited to 32 dimensions. List of the functions : _ArrayAssign : Assigns an array variable by name with the data._ArrayCompare : Checks if two array are identical (size or data)_ArrayDeclare : Creates an empty array with the specified size._ArrayDeclareFromString : Creates an array from an array declaration type string._ArrayEnumValues : Returns all values and indexes of an array in a 2D array._ArrayEval : Returns the array from an array variable name, or the value of an array element by its name_ArrayShuffleMultiDim : Shuffle the whole data of an array._ArrayToDeclarationString : Returns an array declaration string. The returned string can be used with _ArrayDeclareFromString. Some examples : expandcollapse popup_Example1() _Example2() _Example3() _Example4() _Example5() _Example6() _Example7() Func _Example1() Local $aArray1 = _ArrayDeclareFromString("[ [ 1, 2, 3], ['a', 'b', 'c'], [True, False, Null], [], [0x10, 1.3, -10.2E-3] ]") _ArrayDisplay($aArray1, "_ArrayDeclareFromString") EndFunc Func _Example2() Global $aArray2 = [[1,2,""], [4,5,6]] ; Must be a global variable _ArrayDisplay($aArray2, "Before _ArrayAssign") _ArrayAssign("aArray2[0][2]", 3) _ArrayDisplay($aArray2, "After _ArrayAssign") EndFunc Func _Example3() Local $aValues = [ [1,2,3], ['a', True, False] ] _ArrayAssign("aArray3", $aValues) Local $aRet = _ArrayEval("aArray3") _ArrayDisplay($aRet, "_ArrayEval") MsgBox(0, "", "Value for aArray3[1][0] : " & _ArrayEval("aArray3[1][0]") ) EndFunc Func _Example4() Local $aArray3 = [ [[ "000", "001", "002"], ["010", "011", "012"]] , [[ "100", "101", "102"], ["110", "111", "112"]] ] Local $aArray = _ArrayEnumValues($aArray3) _ArrayDisplay($aArray) EndFunc Func _Example5() Local $aArray4 = [ [1, 2, 3], [], ['A string', "That's so ""cool"" !"], [0x10, 1.3, -10.2E-3] ] Local $sDeclaration = _ArrayToDeclarationString($aArray4) MsgBox(0, "", $sDeclaration) EndFunc Func _Example6() Local $aArray5 = [ [[ "000", "001", "002"], ["010", "011", "012"]] , [[ "100", "101", "102"], ["110", "111", "112"]] ] Local $aBefore = _ArrayEnumValues($aArray5) _ArrayDisplay($aBefore, "Before shuffle") _ArrayShuffleMultiDim($aArray5) Local $aAfter = _ArrayEnumValues($aArray5) _ArrayDisplay($aAfter, "After shuffle") EndFunc Func _Example7() Local $aArray6 = [[1, 2], [3, 4]] Local $aArray7 = [["", 2], [3, 4]] Local $iRet = _ArrayCompare($aArray6, $aArray7) If $iRet Then MsgBox(0, "", "Arrays have exactly the same size") Else MsgBox(0, "", "Arrays do not have the same size and dimension.") EndIf $iRet = _ArrayCompare($aArray6, $aArray7, 1) If $iRet Then MsgBox(0, "", "Arrays have exactly the same size and values") Else MsgBox(0, "", "Arrays do not have the same size and values.") EndIf EndFunc ArrayMultiDim.au3 Edited September 17, 2020 by jguinch update / bug correction pixelsearch, robertocm, Trong and 3 others 6 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
czardas Posted January 10, 2016 Share Posted January 10, 2016 I like the idea of _ArrayToDeclarationString() - that is a very useful concept. One suggestion - I think you could add more information about dimension limitations in the comments to these functions. How many dimensions does _ArrayToDeclarationString() cater for? operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jguinch Posted January 10, 2016 Author Share Posted January 10, 2016 You're right, I will change it. This function has no dimension limit ... Try it :-) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
czardas Posted January 10, 2016 Share Posted January 10, 2016 Nice! Local $aSubjects = [[["Art"],["Painting",2,7],["Music",2,3],["Drama",3,4],["Dance",1,10]],[["Science"],["Maths",6,6],["Physics",5,1],["Chemistry",5,6],["Biology",5,6]],[["Sport"],["Football",12,8],["Golf",4,0],["Snooker",1,1],["Chess",10,0]]] operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jguinch Posted January 10, 2016 Author Share Posted January 10, 2016 Thanks.Now, you can do the reverse, build the array from a string :$array = _ArrayDeclareFromString('[[["Art"],["Painting",2,7],["Music",2,3],["Drama",3,4],["Dance",1,10]],[["Science"],["Maths",6,6],["Physics",5,1],["Chemistry",5,6],["Biology",5,6]],[["Sport"],["Football",12,8],["Golf",4,0],["Snooker",1,1],["Chess",10,0]]]') $aEnum = _ArrayEnumValues($array) ; useful for arrays > 2 dimensions _ArrayDisplay($aEnum) czardas 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jguinch Posted September 17, 2020 Author Share Posted September 17, 2020 Edit : _ArrayEnumValues no longer needs to be a recursive function Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Celina76 Posted October 6, 2023 Share Posted October 6, 2023 Hello yy, I searched for what felt like forever until I found this brilliant script! What a great job! 👋 I haven't been working with Autoit for long and I'm having a lot of trouble reading into other people's scripts and even more problems understanding them. So I have a question: I would like to use the "_ArrayAssign" function in a "for ... next" loop and add a new line to the array with each new loop. What would be the easiest way to do this? Thanks in advance Link to comment Share on other sites More sharing options...
jguinch Posted October 9, 2023 Author Share Posted October 9, 2023 Hello @Celina76. Thanks for your message. In fact, the _ArrayAssign function is only useful in very rare cases. I think you have a 99.9% chance of not needing it. I advise you to use the native array declaration method, and in particular ReDim which will allow you to resize an array and therefore add rows easily Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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