Jump to content

Create an Array from column #


Recommended Posts

Hi,

the reason i need this :
somewhere I read that _ArrayUnique() can crash the script when sending it through more then an 2D array

in some cases it does 

I only need to create a 1D Array from column #4  . . .

Edit:     never mind should be something like this i guess ..

Func _1D_ArrayFromColumn(ByRef $aArray, $iColumn = 0, $iCount = 1)
    Local $aArray1D = [UBound($aArray)]
    For $i = $iCount To UBound($aArray) - 1
        _ArrayAdd($a1D, $iColumn)
    Next
    Return $aArray1D
EndFunc   ;==>_1D_ArrayFromColumn

 

Edited by Deye
Link to comment
Share on other sites

Deye,

I don't think any distributed functions work on arrays with more than 2 dimensions.  The following strips column #4 from a 10 column "2D" array...

#include <array.au3>

; create and populate a 10 column 2D array

Local $a2Darray[10][10]

For $1 = 0 To UBound($a2Darray) - 1
    For $2 = 0 To UBound($a2Darray, 2) - 1
        $a2Darray[$2][$1] = StringFormat('%03i-%03i', $1, $2)
    Next
Next

_ArrayDisplay($a2Darray)

; create a 1D array from column #4 of the previous array

Local $a1Darray[UBound($a2Darray)]

For $1 = 0 To UBound($a2Darray) - 1
    $a1Darray[$1] = $a2Darray[$1][3]
Next

_ArrayDisplay($a1Darray, 'Column 4 of 2D array')

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

@czardas - yes, before the code was added the request was crystal clear...

Deye - the code you added and the code I posted do essentially the same thing (except that the array name in the array add is wrong).  Is your question answered?

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

4 hours ago, kylomas said:

@czardas - yes, before the code was added the request was crystal clear...

Not to me. Extracting a column is not going to solve the crash issue. It could have been a work-around solution to a different problem, in which case further information might have proved useful.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...