jbear Posted December 26, 2012 Share Posted December 26, 2012 I have a mulit-dimension array that contains various information about a list of files, as in: Dim $array[10][$last] Enum $f_name, $f_size, $f_create, $f_text, $f_modified, $f_last I want to be able to pass an entry in the array as a single dimension array, like this: My_Func($array[$x]) The function could then operate on just a single dimension of the array I have used some languages that can do this(Although I can't remember which at this moment). Is this possible in AutoIt, or is there another simple way to do this? Objects or structures would be great, but they don't seem to be available. Link to comment Share on other sites More sharing options...
jbear Posted December 26, 2012 Author Share Posted December 26, 2012 Never mind. I found another way. Just pass the 2 dim array, and another parameter that is the 1st dim index, such as: My_func($two_dim_array, $first_dim_index) The other way would have been slightly more elegant in my opinion, but this works as well. Link to comment Share on other sites More sharing options...
kylomas Posted December 26, 2012 Share Posted December 26, 2012 (edited) jbear, Here's one way to do what you asked in your OP. expandcollapse popup; ; pass one row of a 2D array as a 1D array ; #include <array.au3> ; the emun has to be declared BEFORE you use the values enumerated Enum $f_name, $f_size, $f_create, $f_text, $f_modified, $f_last local $array[10][$f_last] = [ _ ['file1',100,'12/12/2009','??????','12/13/2009'], _ ['file2',200,'12/13/2009','??????','12/23/2009'], _ ['file3',300,'12/14/2009','??????','12/24/2009'], _ ['file4',400,'12/15/2009','??????','12/25/2009'], _ ['file5',500,'12/16/2009','??????','12/26/2009'], _ ['file6',600,'12/17/2009','??????','12/27/2009'], _ ['file7',700,'12/18/2009','??????','12/28/2009'], _ ['file8',800,'12/19/2009','??????','12/29/2009'], _ ['file9',900,'12/20/2009','??????','12/30/2009'] _ ] for $1 = 0 to ubound($array,1) - 1 ; loop on 1ST dimension ('1' is default, specified for illustration) $aTmp = 0 ; wipe out temp array for next row local $aTmp[ubound($array,2)] ; define temp array for $2 = 0 to ubound($array,2) - 1 ; loop on 2ND dimension (columns) $aTmp[$2] = $array[$1][$2] ; populate temp array Next do_something_with_it($aTmp) ; go do something with it Next func do_something_with_it($arr) _arraydisplay($arr) endfunc I think the solution that you came up with is the more "elegant" of the two. Pass the array BYREF and avoid any performance hit. Edited December 26, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
water Posted December 26, 2012 Share Posted December 26, 2012 (edited) Depending on the size of the array you could use "ByRef". Then just a pointer to the array is passed to the function and not a complete copy of the array: Func My_func(ByRef $two_dim_array, $first_dim_index) Edited December 26, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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