Sign in to follow this  
Followers 0
Rraney

Flexible Multidimensional arrays, Ie: [0,[0,0]]

11 posts in this topic

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. :D

example return array: [4, ["This, "is", "a", "Test], 2, ["o", "kay"]]

Share this post


Link to post
Share on other sites



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. :D

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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Valik

Share this post


Link to post
Share on other sites

#5 ·  Posted (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)
EndFunc
Randall Edited by randallc

Share this post


Link to post
Share on other sites

Wow :D 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.

Share this post


Link to post
Share on other sites

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

Wow :D 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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by Valik

Share this post


Link to post
Share on other sites

Thanks Valik

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0