Sign in to follow this  
Followers 0
komalo

Adding Array To Another Array ?

4 posts in this topic

hi

i am simply returning an array from my function to another array but i can't use it

the example shows the problem

Local $ThemeBinary[15]

$ThemeBinary[0] = _ExampleReturn()
MsgBox("","",$ThemeBinary[0][1])

Func _ExampleReturn()
    Local $aReturn[4]
    $aReturn[0] = 1
    $aReturn[1] = 2
    $aReturn[2] = 3
    $aReturn[3] = 4
    Return $aReturn
EndFunc

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites



Local $ThemeBinary[15]

$ThemeBinary[0] = _ExampleReturn()
$aAry = $ThemeBinary[0]
MsgBox("","","$aAry[1]=" & $aAry[1])

Func _ExampleReturn()
    Local $aReturn[4]
    $aReturn[0] = 1
    $aReturn[1] = 2
    $aReturn[2] = 3
    $aReturn[3] = 4
    Return $aReturn
EndFunc

Share this post


Link to post
Share on other sites

komalo,

picaxe has fgiven you a valid solution, but I thought a bit more explanation might be useful.

With your example, you are putting the entire returned array (all 4 elements) into the first array of $aThemeBinary. Look at this code to see what I mean:

#include <Array.au3>

Local $aThemeBinary[15]

$aThemeBinary[0] = _ExampleReturn()

_ArrayDisplay($aThemeBinary, "$aThemeBinary")
_ArrayDisplay($aThemeBinary[0], "$aThemeBinary[0]")

Func _ExampleReturn()
    Local $aReturn[4]
    $aReturn[0] = 1
    $aReturn[1] = 2
    $aReturn[2] = 3
    $aReturn[3] = 4
    Return $aReturn
EndFunc

Then you are trying to use $ThemeBinary as a 2-D array in the MsgBox call which gives you the "Array variable has incorrect number of subscripts or subscript dimension range exceeded" error. If you want to resize $ThemeBinary to the same size as the returned array, then use this code:

#include <Array.au3>

Local $aThemeBinary[15]

$aThemeBinary = _ExampleReturn()

_ArrayDisplay($aThemeBinary, "$aThemeBinary")

Func _ExampleReturn()
    Local $aReturn[4]
    $aReturn[0] = 1
    $aReturn[1] = 2
    $aReturn[2] = 3
    $aReturn[3] = 4
    Return $aReturn
EndFunc

If you want to keep $aThemeBinary at its original size than you will have to change the code to this:

#include <Array.au3>

Local $aThemeBinary[15]

$aArray = _ExampleReturn()

For $i = 0 To UBound($aArray) - 1
    $aThemeBinary[$i] = $aArray[$i]
Next

_ArrayDisplay($aThemeBinary, "$aThemeBinary")

Func _ExampleReturn()
    Local $aReturn[4]
    $aReturn[0] = 1
    $aReturn[1] = 2
    $aReturn[2] = 3
    $aReturn[3] = 4
    Return $aReturn
EndFunc

If you want to keep all the returned array inside the first element of $aThemeBinary, then you have to go with picaxe's code and extract the returned elements into another array before using them:

#include <Array.au3>

Local $aThemeBinary[15]

$aThemeBinary[0] = _ExampleReturn()

$aArray = $aThemeBinary[0]

_ArrayDisplay($aThemeBinary, "$aThemeBinary")
_ArrayDisplay($aArray, "$aArray")

Func _ExampleReturn()
    Local $aReturn[4]
    $aReturn[0] = 1
    $aReturn[1] = 2
    $aReturn[2] = 3
    $aReturn[3] = 4
    Return $aReturn
EndFunc

I hope that clears up any confusion over what was happening. However, I would draw your attention to the following from the Help file:

"...an AutoIt-Array could also contain different types, even other Arrays...This has not been strictly forbidden in AutoIt. However, it is NOT ADVISABLE to mix different datatypes in an Array. Especially the use of an Array inside another Array will severely affect the execution speed of your script."

So be careful if you do decide you want to keep your returned array inside $aThemeBinary - it might come back to bite you!

Please ask if anything is unclear.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thank you all

it's clear for me now Melba23

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

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