komalo Posted February 4, 2009 Share Posted February 4, 2009 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] Link to comment Share on other sites More sharing options...
picaxe Posted February 4, 2009 Share Posted February 4, 2009 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2009 Moderators Share Posted February 4, 2009 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 EndFuncThen 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 EndFuncIf 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 EndFuncIf 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 EndFuncI 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
komalo Posted February 4, 2009 Author Share Posted February 4, 2009 (edited) thank you allit's clear for me now Melba23 Edited February 4, 2009 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] 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