ArrayList: AddRange

AddRange

Adds the items from a collection to the list.



 Public Sub AddRange(
	  ByRef Source As Variant )

Parameters

Source
[ByRef] Variant. The collection of items to add.

Remarks

The collection can be a VBA.Collection, ICollection object, or an Array.

The elements are added to the end of the list in the same order as a For..Each loop produces.

If the number of elements to be added is more than the available capacity in the ArrayList, then the capacity is increased to accommodate the collection of elements.

Exceptions

Exception TypeCondition
ArgumentNullException c is an uninitialized array.
-or-
c is Nothing.
NotSupportedException The ArrayList is read-only
-or-
The ArrayList is fixed size.
InvalidCastExceptionc is not a VBA.Collection, ICollection object, or an Array.

Examples

The following example demonstrates using the AddRange method to add a collection of items.

Private Sub Main()
    Dim List As New ArrayList
    Dim Words() As String
    
    Words = NewStrings("The", "fox", "jumps", "over", "the", "dog")
    
    List.AddRange Words
    
    PrintValues List
End Sub

Private Sub PrintValues(ByVal Source As IEnumerable)
    Dim Value As Variant
    
    Console.WriteValue vbTab
    
    For Each Value In Source
        Debug.Print CorString.Format("{0} ", Value);
    Next Value
End Sub

' This example produces the following output.
'
'    The fox jumps over the dog

See Also

Project CorLib Overview

Class ArrayList Overview

ICollection

Capacity

Count

Add

InsertRange

SetRange

RemoveRange