Visual Basic 6 function "array_merge"

Go back

Below you'll find the source for the Visual Basic 6 function array_merge.

Attribute VB_Name = "modArrayMerge"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

''
' Merge two or more arrays
' Same syntax as the PHP function 'array_merge'
' See also: http://www.php.net/manual/en/function.array-merge.php
' @param    array   array1      The first array
' @param    array   array2      The second array
' @param    array   array3      etc.
' @return   array               All arrays merged into one
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Private Function array_merge(ParamArray Arrays() As Variant) As Variant
    Dim retval() As String, i As Integer, j As Integer, cnt As Integer
    For i = LBound(Arrays) To UBound(Arrays)
        For j = LBound(Arrays(i)) To UBound(Arrays(i))
            ReDim Preserve retval(0 To cnt)
            retval(cnt) = Arrays(i)(j)
            cnt = cnt + 1
        Next j
    Next i
    array_merge = retval
End Function