$MyArray1=SetupMyArray(1) $MyArray2=SetupMyArray(2) $MyArray3=SetupMyArray(3) ;... $I = DetermineWhichArrayToWorkWith() If $i = 1 then WorkWithArray($MyArray1) ElseIf $i = 2 then WorkWithArray($MyArray2) ElseIf $i = 3 then WorkWithArray($MyArray3) EndIf
(And obviously the code gets bigger and messier with the more arrays you have to deal with)
You can create an array to contain your arrays:
Dim $ArrayParent For $i = 1 to 3 $ArrayParent[$i] = SetUpMyArray($i) Next $I = DetermineWhichArrayToWorkWith() WorkWithArray($ParentArray[$i])
The only problem is that you can't access the child array elements directly. For instance, say you have a 1-dimensional array inside another 1-dimensional array. you couldn't access this by $Array, because that's reserved for 2-dimensional arrays. In fact, AutoIt gives no native way to deal with a nested array. The only thing you can do is either copy the array out to a temp array and work with it there, or past the parent element to a function that expects an array for input.
Anyway, I writing a set of UDFs for working with nested arrays. Here's the first 4 functions I've whipped up:
_ArrayNGet(ByRef $Array, $Path)
_ArrayNSet(ByRef $Array, $Path, $Value)
_ArrayNUBound(ByRef $Array, $Path, $Dimension)
_ArrayNReDim(ByRef $Array, $Path, $Dimensions)
They should be pretty self-explainatory from their names. Here's the parameters:
$Array = the parent array
$Path = the path to follow down to find the element you want to deal with. The path is a string, which could look like this: '3;5,6;4' which represents the 4th element of a 1-dimensional array, inside the  element inside a 2-dimensional array, inside the 3rd element of a 1-dimensional array.
$Value is the value to set to the given element (which of course could be another array)
$Dimension is the dimension to return, same as in the built-in UBound() function
$Dimensions is a string like '1,2,3' Which tells the dimensions to Dim the array to.
Note: These functions have the limitation of only being able to deal with 1-6 dimensional arrays, but they can be easily adapted to handle more.
Another note: These functions, on failure, will return a string containing a message describing why they failed. So in your code you could do this to help troubleshoot:
$i = _ArrayNGet($MyArray, '3;2,5') If @Error then MsgBox(0,'Error ' & @Error, $i)
Edited by blindwig, 27 June 2005 - 01:51 AM.