#include <Array.au3>
Dim $avArray[5][3] = [ _
[5, 20, 8], _
[4, 32, 7], _
[3, 16, 9], _
[2, 35, 0], _
[1, 19, 6]]
$vValue="a|b|c"
_ArrayDisplay($avArray)
__ArrayAdd($avArray, $vValue)
_ArrayDisplay($avArray)
; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayAdd
; Description ...: Adds a specified value at the end of an existing array. Also will add a delimited string to a 2D array.
; Syntax.........: _ArrayAdd(ByRef $avArray, $vValue)
; Parameters ....: $avArray - Array to modify
; $vValue - Value to add
; Return values .: Success - Index of last added item
; Failure - -1, sets @error
; |1 - $avArray is not an array
; |2 - $avArray is not a 1 or 2 dimensional array
; |3 - $vValue has too many subitems
; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
; Modified.......: Ultima - code cleanup, BrewManNH - 2D array support
; Remarks .......:
; Related .......: _ArrayConcatenate, _ArrayDelete, _ArrayInsert, _ArrayPop, _ArrayPush
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func __ArrayAdd(ByRef $avArray, $vValue, $sSeparator = "|")
If Not IsArray($avArray) Then Return SetError(1, 0, -1)
If UBound($avArray, 0) > 2 Then Return SetError(2, 0, -1)
Local $avValue = StringSplit($vValue, $sSeparator)
If Not @error Then
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $avValue = ' & $avValue & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$iSubMax = $avValue[0]
If $iSubMax <> UBound($avArray, 2) Then Return SetError(3, 0, 0)
EndIf
If UBound($avArray, 0) = 1 Then
Local $iUBound = UBound($avArray)
ReDim $avArray[$iUBound + 1]
$avArray[$iUBound] = $vValue
Return $iUBound
Else
Local $iUBound = UBound($avArray)
ReDim $avArray[$iUBound + 1][$iSubMax]
For $i = 0 To $iSubMax - 1
$avArray[$iUBound][$i] = $avValue[$i + 1]
Next
Return $iUBound
EndIf
EndFunc ;==>_ArrayAdd