Queue: Clear

Clear

Removes all items from the Queue.



 Public Sub Clear ( )

Remarks

Count is set to zero, and references to other objects from elements of the collection are also released.

The capacity remains unchanged. To reset the capacity of the Queue, call TrimToSize. Trimming an empty Queue sets the capacity of the Queue to the default capacity.

Examples

The following example shows how to clear the values of the Queue.

Public Sub Main()
    Dim MyQ As New Queue
    
    MyQ.Enqueue "The"
    MyQ.Enqueue "quick"
    MyQ.Enqueue "brown"
    MyQ.Enqueue "fox"
    MyQ.Enqueue "jumped"
    
    ' Displays the count and values of the queue.
    Debug.Print "Initially,"
    Debug.Print "   Count    : " & MyQ.Count
    Debug.Print "   Values:";
    PrintValues MyQ
    
    ' Clears the queue.
    MyQ.Clear
       
    ' Displays the count and values of the queue.
    Debug.Print "After Clear,"
    Debug.Print "   Count    : " & MyQ.Count
    Debug.Print "   Values:";
    PrintValues MyQ
End Sub

Private Sub PrintValues(ByVal MyQ As Queue)
    Dim Item As Variant
    
    For Each Item In MyQ
        Debug.Print "    " & Item;
    Next
    
    Debug.Print
End Sub

' This example code produces the following output.
'
'    Initially,
'       Count    : 5
'       Values:    The    quick    brown    fox    jumped
'    After Clear,
'       Count    : 0
'       Values:

See Also

Project CorLib Overview

Class Queue Overview

TrimToSize