Jump to content

_ArrayAdd


Recommended Posts

Hello everyone!

I try to spilit 2 array with different size without good point.

Local $base[1][2][2] = [ _      

    [ _

        [1, 2], _

        [3, 4] _  

    ] _         

]

Local $add[5][2] = [ _

    [1, 2], _

    [3, 4], _

    [5, 6], _

    [7, 8], _

    [9, 10] _

]

  _ArrayAdd($base, $add) ;==> dont work cuz support only 1D or 2D arrays.

Any Idea?

Regards, 

Rafal

Link to comment
Share on other sites

I found way by myself, here code if someone need.

;==============================================================================================================================
; Function:         _TableInsert ($table, $arg)
;
; Description:      Insert argumnet into array.
; Parameter(s):     $table - Array to insert.
;                   $arg - Item to insert can be example:
;                       $arg = 1
;                       $arg = 'Hello World'
;                       $arg[5] = [1, 2, 3, 4, 5]
;                       $arg[2][2] = [[1, 2], [3, 4]]
;
; Return Value(s):  On Success - Returns new array.
;                   On Failure - Returns empty array.
;
; Author:           Ascer
;=================================================================================================================================
Func _TableInsert ($table, $arg)
    Local $size = UBound($table) + 1
    Local $table2[$size]
    For $i = 0 To $size - 2
        $table2[$i] = $table[$i]
    Next
    $table2[$size - 1] = $arg
    Return $table2
EndFunc

How to use:

Local $store[0]

ConsoleWrite('Size of array before inserting: ' & Ubound($store) & @CRLF)

Local $add = [ _
    [ _
        [1, 2, 3], _
        [1, 2, 3, 4], _
        [1, 2, 3, 4, 5] _
    ] _
]

Local $new_array = _TableInsert($store, $add)
ConsoleWrite('New array size: ' & Ubound($new_array) & @CRLF)

; How to get access to each sub_array in main $new_array

Local $add_array = $new_array[0]
For $i = 0 To UBound($add_array, 1) - 1
    For $j = 0 To UBound($add_array, 2) - 1
        ConsoleWrite('Browse index: ' & $j & @CRLF)
        For $h = 0 To UBound($add_array, 3) - 1
            ConsoleWrite('item[' & $h & '] : ' & $add_array[$i][$j][$h] & @CRLF)
        Next
    Next
Next

Console output:

Size of array before inserting: 0
New array size: 1
Browse index: 0
item[0] : 1
item[1] : 2
item[2] : 3
item[3] : 
item[4] : 
Browse index: 1
item[0] : 1
item[1] : 2
item[2] : 3
item[3] : 4
item[4] : 
Browse index: 2
item[0] : 1
item[1] : 2
item[2] : 3
item[3] : 4
item[4] : 5

btw. this item[3]  with empty string seems to bad logic while AutoIt was created. Arrays here are one big misstake ;( 

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