21 | 08 | 2017

Copy Array

Public Sub CopyArray(FromArray As Variant, ToArray As Variant)

'Copies source array to dest array
'ToArray should be dynamic array

Dim l As Long, lUBound As Long, lLBound As Long

If (Not IsArray(FromArray)) Or (Not IsArray(ToArray)) Then Exit Sub

lLBound = LBound(FromArray)
lUBound = UBound(FromArray)

ReDim ToArray(lLBound To lUBound)
For l = lLBound To lUBound
ToArray(l) = FromArray(l)
Next
End Sub

Sub TestCopyArry()

Dim i(2) As Integer, j() As Integer
Dim iCtr As Integer

i(0) = 5
i(1) = 8
i(2) = 10
CopyArray i, j
For iCtr = 0 To UBound(j)
Debug.Print j(iCtr)
Next

End Sub
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2330620
Latest Articles