Stack: Clear

Clear

Removes all items from the Stack.



 Public Sub Clear ( )

Remarks

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

Examples

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

Public Sub Main()
    ' Creates an initializes a new Stack.
    Dim MyStack As New Stack
    MyStack.Push "The"
    MyStack.Push "quick"
    MyStack.Push "brown"
    MyStack.Push "fox"
    MyStack.Push "jumped"
    
    ' Displays the count and values of the Stack.
    Debug.Print "Initially,"
    Debug.Print "   Count    : " & MyStack.Count
    Debug.Print "   Values:";
    PrintValues MyStack
    
    ' Clears the Stack.
    MyStack.Clear
    
    ' Displays the count and values of the Stack.
    Debug.Print "After Clear,"
    Debug.Print "   Count    : " & MyStack.Count
    Debug.Print "   Values:";
    PrintValues MyStack
End Sub

Private Sub PrintValues(ByVal MyCollection As IEnumerable)
    Dim Item As Variant
    
    For Each Item In MyCollection
        Debug.Print vbTab & Item;
    Next
    
    Debug.Print
End Sub

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

See Also

Project CorLib Overview

Class Stack Overview