Also, instead of writing a loop every time you can wrap it in an extension method. Create a Module (name it whatever you like) and add this method to it, with Global scope.
[code]Function duplicate(extends arr() As STRING) As STRING()
dim last As integer = arr.Ubound
dim r() As STRING
redim r(last)
for i As integer = 0 to last
r(i) = arr(i)
next
return r
End Function[/code]
Now you can copy your arrays like this
array2 = array1.duplicate
For other types of arrays, Integer, Double, etc just add the method to the Module again but replace the 3 occurrences of STRING with Integer, Double, etc.
Making a version with “Object” will work for all object type arrays, Folderitem(), Window(), MyClass(), etc. But it’s not so handy because it only returns an array typed as Object() whereas you typically want FolderItem(), Window(), etc.
To duplicate/copy an object array to a specific object array type you need to pass that specific array type to the method instead of returning a generic Object one.
[code]Sub duplicateInto(extends arr() As Object, dest() As Object)
if dest = nil then return
dim last As integer = arr.Ubound
redim dest(last)
for i As integer = 0 to last
dest(i) = arr(i)
next
End Sub[/code]
and so it’s used a little differently
[code]dim objs1() As PushButton = Array(PushButton1, PushButton2, PushButton3)
dim objs2() As PushButton
objs1.duplicateInto( objs2 )[/code]
Note that one of the differences is the destination array has to be dimmed before the duplication call. With String arrays it can be done on the same line.
dim array2() As String = array1.duplicate