Assigning One Array to Another

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

If two dynamic arrays have the same data type, you can assign one array to another. Assigning one array to another of the same type is quick because the first array is simply pointed to the memory location that stores the second array.

For example, the following code fragment assigns one string array to another:

Dim astr1() As String
Dim astr2(0 To 9) As String

astr1 = astr2

Note   This type of assignment works only for arrays of the same type. The two arrays must both be dynamic arrays, and they must be declared as the exact same type: if one is type String, the other must be type String. It cannot be type Variant or any other data type. If you want to assign one array's elements to an array of a different type, you must create a loop and assign each element one at a time.

See Also

Understanding Arrays | Creating Arrays | Arrays and Variants | Returning an Array from a Function | Passing an Array to a Procedure | Sorting Arrays | Using the Filter Function to Search String Arrays | Using a Binary Search Function to Search Numeric Arrays | Searching a Dictionary