Sign in to follow this  
Followers 0
Kyan

2D arrays, merge same size arrays (add columns)

6 posts in this topic

Hi, there's any function to do this?

Or it needs to be done one by one? (redim $arraybase[ubond($arraybase)][ubond($arraybase,2)+1]...)

I tried with _arrayadd example but my output is the same:

Local $aArray, $sFill

Local $aArray_Base[2][2] = [["Item 0 - 0", "Item 0 - 1"],["Item 1 - 0", "Item 1 - 1"]]
_ArrayDisplay($aArray_Base, "2D - Base array")

; Add item delimited string
$aArray = $aArray_Base
$sFill = "New Item 2 - 0|New Item 2 - 1"
_ArrayAdd($aArray, $sFill)
_ArrayDisplay($aArray, "2D - Item delimited") 

thank you, and sorry for the simple question


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites



Maybe use UBound instead of ubond?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Kyan,

Your code as posted works fine for me. :)

As the 2 arrays have the same number of columns you can also concatenate them a shown here: ;)

#include <Array.au3>

Local $aArray, $sFill

Local $aArray_Base[2][2] = [["Item 0 - 0", "Item 0 - 1"],["Item 1 - 0", "Item 1 - 1"]]

_ArrayDisplay($aArray_Base, "2D - Base array")

; Add item delimited string
$aArray = $aArray_Base
$sFill = "Add Item 2 - 0|Add Item 2 - 1"

_ArrayAdd($aArray, $sFill)

_ArrayDisplay($aArray, "2D - Item delimited")

; Or concatenate 2 arrays
$aArray = $aArray_Base
Local $aArray_Add[1][2] = [["Conc Item 2 - 0", "Conc Item 2 - 1"]]

_ArrayConcatenate($aArray, $aArray_Add)

_ArrayDisplay($aArray, "2D - Concatenated"
One final question - which AutoIt version do you use? The new Array library was added in 3.3.12.0 and the old versions had less functionality - which may explain why the functions do not work for you. :)

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)

Melba doesn't the topic title say add columns ?

#include <Array.au3>

Local $aArray[3][2] = [["Item 0 - 0", "Item 0 - 1"],["Item 1 - 0", "Item 1 - 1"],["Item 2 - 0", "Item 2 - 1"]]
Local $aFill[3] = ["Add Item 2 - 0", "Add Item 2 - 1", "Add Item 2 - 2"]
_ArrayDisplay($aArray)

$u = UBound($aArray)
$c = UBound($aArray, 2)
ReDim $aArray[$u][$c + 1]

For $i = 0 to $u - 1
   $aArray[$i][$c] = $aFill[$i]
Next
_ArrayDisplay($aArray, "Redimmed")

; OR

Local $aArray[3][2] = [["Item 0 - 0", "Item 0 - 1"],["Item 1 - 0", "Item 1 - 1"],["Item 2 - 0", "Item 2 - 1"]]
; Local $sFill = "Add Item 2 - 0|Add Item 2 - 1|Add Item 2 - 2"
Local $aFill[1][3] = [["Add Item 2 - 0","Add Item 2 - 1","Add Item 2 - 2"]]


_ArrayTranspose($aArray)
; _ArrayAdd($aArray, $sFill)
_ArrayAdd($aArray, $aFill)
_ArrayTranspose($aArray)

_ArrayDisplay($aArray, "Concatenated")
Edited by mikell
1 person likes this

Share this post


Link to post
Share on other sites

mikell,

Indeed it does - but the example code suggests that the OP actually means "Rows" as the data to be added is obviously a new row. Let us wait and see. :)

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

Maybe use UBound instead of ubond?

Yes, I wrote that from memory, was late didn't check spelling :)

Kyan,

Your code as posted works fine for me. :)

As the 2 arrays have the same number of columns you can also concatenate them a shown here: ;)

One final question - which AutoIt version do you use? The new Array library was added in 3.3.12.0 and the old versions had less functionality - which may explain why the functions do not work for you. :)

M23

 

@AutoItVersion gives me "3.3.10.2", hitted F1 and my help file doesn't have so many parameters on the _ArrayAdd function

I wanted to add a nem column by merging a 1D array, like $baseArray[n][c+1], though _arrayadd could do that job :)

Thank you

 

Melba doesn't the topic title say add columns ?

#include <Array.au3>

Local $aArray[3][2] = [["Item 0 - 0", "Item 0 - 1"],["Item 1 - 0", "Item 1 - 1"],["Item 2 - 0", "Item 2 - 1"]]
Local $aFill[3] = ["Add Item 2 - 0", "Add Item 2 - 1", "Add Item 2 - 2"]
_ArrayDisplay($aArray)

$u = UBound($aArray)
$c = UBound($aArray, 2)
ReDim $aArray[$u][$c + 1]

For $i = 0 to $u - 1
   $aArray[$i][$c] = $aFill[$i]
Next
_ArrayDisplay($aArray, "Redimmed")

; OR

Local $aArray[3][2] = [["Item 0 - 0", "Item 0 - 1"],["Item 1 - 0", "Item 1 - 1"],["Item 2 - 0", "Item 2 - 1"]]
; Local $sFill = "Add Item 2 - 0|Add Item 2 - 1|Add Item 2 - 2"
Local $aFill[1][3] = [["Add Item 2 - 0","Add Item 2 - 1","Add Item 2 - 2"]]


_ArrayTranspose($aArray)
; _ArrayAdd($aArray, $sFill)
_ArrayAdd($aArray, $aFill)
_ArrayTranspose($aArray)

_ArrayDisplay($aArray, "Concatenated")

1st Example works perfectly, thank you very much :D

2nd is not working,maybe due to have a old autoit version, need to update it. But good thinking, transpose them to two rows, add a new row, and then put them pack together as  columns :)


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

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