Rraney Posted June 8, 2006 Share Posted June 8, 2006 I can get around this, but its messy. Is it possible receive and array from a function that would have arrays inside it? The kicker is, I have no idea how large the returning array will be when it is returned. example return array: [4, ["This, "is", "a", "Test], 2, ["o", "kay"]] Link to comment Share on other sites More sharing options...
seandisanti Posted June 8, 2006 Share Posted June 8, 2006 I can get around this, but its messy. Is it possible receive and array from a function that would have arrays inside it? The kicker is, I have no idea how large the returning array will be when it is returned. example return array: [4, ["This, "is", "a", "Test], 2, ["o", "kay"]]yes... here's a simple example #include<array.au3> Dim $array = ReturnArrayOfArrays() Func ReturnArrayOfArrays() Dim $ReturnArray[2][2] $ReturnArray[0][0] = 1 $ReturnArray[0][1] = 2 $ReturnArray[1][0] = 3 $ReturnArray[1][1] = 4 Return $ReturnArray EndFunc ;==>ReturnArrayOfArrays For $x = 0 To 1 For $y = 0 To 1 MsgBox(0, "Element [" & $x & "][" & $y & "]", $array[$x][$y]) Next Next Link to comment Share on other sites More sharing options...
Don N Posted June 8, 2006 Share Posted June 8, 2006 If I understand the question right I think this code shows making arrays as elements of another array can be done and an example of it: #include <Array.au3> Func AofA() Dim $array = _ArrayCreate( 0 ) For $iter = 0 To Int( Random( 0, 10 ) ) Local $temp_array = _ArrayCreate( 0 ) For $iter2 = 0 To Int( Random( 0, 10 ) ) _ArrayAdd( $temp_array, $iter2 ) Next $temp_array[0] = UBound( $temp_array ) - 1 _ArrayAdd( $array, $temp_array ) Next $array[0] = UBound( $array ) - 1 Return $array EndFunc $myArray = AofA() For $i = 1 To $myArray[0] _ArrayDisplay( $myArray[$i], "$myArray[ " & $i & " ] of " & $myArray[0] & " elements." ) Next Hope that helps.... _____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper Link to comment Share on other sites More sharing options...
Valik Posted June 8, 2006 Share Posted June 8, 2006 (edited) cameronsdad, I don't think that is what the OP wants.Rraney, yes, you can store an array inside an array element but in order to access the "nested" array you have to copy it into another variable:Global $Array[2] Global $SubArray[4] = [ "Red", "Yellow", "Orange", "Blue" ] $Array[0] = "Foo" ; This stores SubArray inside $Array[1] $Array[1] = $SubArray ; If we want to access $SubArray, you have to copy it out to a variable Global $SubArray2 = $Array[1] For $i = 0 To UBound($SubArray2) - 1 MsgBox(4096, "", $i & "=" & $SubArray2[$i]) NextoÝ÷ Ù.¹Æ§¹§zË"¶X¤zØb±«¢+ØÀÌØíÉÉålÅulÁtìQ¡¥Ì¥Ì¹½ÐÅÕ½ÐíIÅÕ½Ðì°Ñ¡¥Ì¥ÌÍå¹ÑàÉɽȰÀÌØíÉÉä¥Ì½¹¥µ¹Í¥½¹°(Edit: Of course, once you build $Array, you could just return it from a function like normal. Edited June 8, 2006 by Valik Link to comment Share on other sites More sharing options...
randallc Posted June 8, 2006 Share Posted June 8, 2006 (edited) Hi, my 2 penneth of what is requested...??? ;ArrayOfArays.au3 #include<array.au3> dim $ar_ArrayL1[1] _StringSplit($ar_ArrayL1,'[1][2,3,4][3][4,5][6,7]',"][",1) _ArrayDisplay($ar_ArrayL1,"") dim $ar_Array[ubound ($ar_ArrayL1)] for $i=1 to ubound ($ar_ArrayL1)-1 $ar_Array[$i]=StringSplit($ar_ArrayL1[$i],",") _ArrayDisplay($ar_Array[$i],"$ar_ArrayL1[$i]") Next Func _StringSplit(byref $ar_Array,$s_String, $Separator, $i_Flag) $ar_Array=StringSplit(StringTrimRight(StringTrimLeft($s_String,1),1), $Separator, $i_Flag) EndFuncRandall Edited June 8, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Rraney Posted June 8, 2006 Author Share Posted June 8, 2006 Wow That is exactly what I needed! I was having a Devil of a time trying to access the array(s) inside the returned array. - RSR cameronsdad, I don't think that is what the OP wants. Rraney, yes, you can store an array inside an array element but in order to access the "nested" array you have to copy it into another variable: Global $Array[2] Global $SubArray[4] = [ "Red", "Yellow", "Orange", "Blue" ] $Array[0] = "Foo" ; This stores SubArray inside $Array[1] $Array[1] = $SubArray ; If we want to access $SubArray, you have to copy it out to a variable Global $SubArray2 = $Array[1] For $i = 0 To UBound($SubArray2) - 1 MsgBox(4096, "", $i & "=" & $SubArray2[$i]) NextoÝ÷ Ù.¹Æ§¹§zË"¶X¤zØb±«¢+ØÀÌØíÉÉålÅulÁtìQ¡¥Ì¥Ì¹½ÐÅÕ½ÐíIÅÕ½Ðì°Ñ¡¥Ì¥ÌÍå¹ÑàÉɽȰÀÌØíÉÉä¥Ì½¹¥µ¹Í¥½¹°( Edit: Of course, once you build $Array, you could just return it from a function like normal. Link to comment Share on other sites More sharing options...
Valuater Posted June 8, 2006 Share Posted June 8, 2006 ok... this may look real bad... but whats wrong with my theory here??? #include<array.au3> #include<string.au3> Dim $ReturnArray[5] $ReturnArray[0] = 4 $ReturnArray[1] = StringSplit("This, is, a, Test",",") $ReturnArray[2] = StringSplit("o, kay", ",") $ReturnArray[3] = StringSplit("This, is, another, Test",",") $ReturnArray[4] = StringSplit("well, done", ",") For $x = 1 To $ReturnArray[0] For $y = 1 To $ReturnArray[$x][0] -1 MsgBox(0, "Element [" & $x & "][" & $y & "]", $ReturnArray[$x][$y]) Next Next ok... be kind 8) Link to comment Share on other sites More sharing options...
JSThePatriot Posted June 8, 2006 Share Posted June 8, 2006 ok... this may look real bad... but whats wrong with my theory here??? #include<array.au3> #include<string.au3> Dim $ReturnArray[5] $ReturnArray[0] = 4 $ReturnArray[1] = StringSplit("This, is, a, Test",",") $ReturnArray[2] = StringSplit("o, kay", ",") $ReturnArray[3] = StringSplit("This, is, another, Test",",") $ReturnArray[4] = StringSplit("well, done", ",") For $x = 1 To $ReturnArray[0] For $y = 1 To $ReturnArray[$x][0] -1 MsgBox(0, "Element [" & $x & "][" & $y & "]", $ReturnArray[$x][$y]) Next Next ok... be kind 8) I am unable to get this code to run under the latest beta. JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
Rraney Posted June 8, 2006 Author Share Posted June 8, 2006 Wow That is exactly what I needed! I was having a Devil of a time trying to access the array(s) inside the returned array. - RSR cameronsdad, I don't think that is what the OP wants. Rraney, yes, you can store an array inside an array element but in order to access the "nested" array you have to copy it into another variable: Global $Array[2] Global $SubArray[4] = [ "Red", "Yellow", "Orange", "Blue" ] $Array[0] = "Foo" ; This stores SubArray inside $Array[1] $Array[1] = $SubArray ; If we want to access $SubArray, you have to copy it out to a variable Global $SubArray2 = $Array[1] For $i = 0 To UBound($SubArray2) - 1 MsgBox(4096, "", $i & "=" & $SubArray2[$i]) NextoÝ÷ Ù.¹Æ§¹§zË"¶X¤zØb±«¢+ØÀÌØíÉÉålÅulÁtìQ¡¥Ì¥Ì¹½ÐÅÕ½ÐíIÅÕ½Ðì°Ñ¡¥Ì¥ÌÍå¹ÑàÉɽȰÀÌØíÉÉä¥Ì½¹¥µ¹Í¥½¹°( Edit: Of course, once you build $Array, you could just return it from a function like normal. Link to comment Share on other sites More sharing options...
Valik Posted June 8, 2006 Share Posted June 8, 2006 (edited) Valuater, I already answered that in my post. You can not access the elements of the array in that manner. You must copy the contents of the array out to a variable to access the nested array:#include<array.au3> #include<string.au3> Global $ReturnArray[5] $ReturnArray[0] = 4 $ReturnArray[1] = StringSplit("This, is, a, Test",",") $ReturnArray[2] = StringSplit("o, kay", ",") $ReturnArray[3] = StringSplit("This, is, another, Test",",") $ReturnArray[4] = StringSplit("well, done", ",") For $x = 1 To $ReturnArray[0] Global $NestedArray = $ReturnArray[$x] For $y = 1 To $NestedArray[0] MsgBox(0, "", "$ReturnArray[" & $x & "]" & @CR & "$NestedArray[" & $y & "]" & @CR & $NestedArray[$y]) Next Next Edited June 8, 2006 by Valik Link to comment Share on other sites More sharing options...
Valuater Posted June 9, 2006 Share Posted June 9, 2006 Thanks Valik 8) 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