Jump to content

Recommended Posts

Posted (edited)

Im sure this is easy for some of the more advanced users in here. But one of my biggest issue with most of the array stuff is that it is built for 1d arrays only. Most of the arrays I use are 2d or are 2d by the time I get all the info I need. Anyway thought this might help some people that are still in the learning and medium levels of Autoit programing. I plan on releasing more as I need it or requested. :)

The code will always resize the target array to the bigger of the target and source arrays.

; #FUNCTION# ====================================================================================================



================
; Name...........: _ArrayConcatenate2d
; Description ...: Concatenate two 2d arrays
; Syntax.........: _ArrayConcatenate ( $avArrayTarget, $avArraySource )
; Parameters ....: $avArrayTarget - The array to concatenate onto
;                 $avArraySource - The array to concatenate from
; Return values .: Success - $avArrayTarget's new size
;                 Failure - 0, sets @error to:
;                 |1 - $avArrayTarget is not an array
;                 |2 - $avArraySource is not an array
; Author ........: Ultima
; Modified.......: Nhardel
; Remarks .......:
; Related .......: _ArrayAdd, _ArrayPush
; Link ..........;
; Example .......; no
; ====================================================================================================



===========================
Func _ArrayConcatenate2d(ByRef $avArrayTarget, Const ByRef $avArraySource)
    If Not IsArray($avArrayTarget) Then Return SetError(1, 0, 0)
    If Not IsArray($avArraySource) Then Return SetError(2, 0, 0)

    Local $xUBoundTarget = UBound($avArrayTarget), $xUBoundSource = UBound($avArraySource)
    if Ubound($avArrayTarget,2) <= Ubound($avArraySource,2) Then
        $yUBoundTarget = Ubound($avArraySource,2)
    Else
        $yUBoundTarget = Ubound($avArrayTarget,2)
    EndIf

    ReDim $avArrayTarget[$xUBoundTarget + $xUBoundSource][$yUBoundTarget]
    For $h = 0 to $yUBoundTarget-1
        For $i = 0 To $xUBoundSource - 1
            $avArrayTarget[$xUBoundTarget + $i][$h] = $avArraySource[$i][$h]
        Next
    Next
    Return $avArrayTarget
EndFunc;==>_ArrayConcatenate
Edited by nhardel
Posted

I think you have some typos in there. You're mixing your $x... with your $i...:

(29,41) : WARNING: $iUBoundTarget: possibly used before declaration.
    ReDim $avArrayTarget[$iUBoundTarget +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
(29,57) : WARNING: $iUBoundSource: possibly used before declaration.
    ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

WBD

Posted

I think you have some typos in there. You're mixing your $x... with your $i...:

(29,41) : WARNING: $iUBoundTarget: possibly used before declaration.
    ReDim $avArrayTarget[$iUBoundTarget +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
(29,57) : WARNING: $iUBoundSource: possibly used before declaration.
    ReDim $avArrayTarget[$iUBoundTarget + $iUBoundSource]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

WBD

Sorry It has been fixed :)

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
  • Recently Browsing   0 members

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