Sign in to follow this  
Followers 0
jbear

Pass single dimension of Muti-dimension Array?

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

jbear,

Here's one way to do what you asked in your OP.

;
; 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 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

Share this post


Link to post
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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