The VBA Stack represents a simple last-in-first-out (LIFO) non-generic collection of objects. The VBA Stack is useful in situations when you want to first process items which were added last.
The VBA Stack can be compared to a stack of cards – you can put cards on top in a certain order but then you are expected to pick them up in the reverse order.
Other VBA Data Structures
VBA Stack example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Dim stack as Object Set stack = CreateObject("System.Collections.Stack") 'Create Stack stack.Push "Hello" stack.Push "There" stack.Push "Mr" stack.Push "Smith" peekAtTopOfStack = stack.Peek() doesContain = stack.Contains("htrh") 'Result: False doesContain = stack.Contains("Hello") 'Result: True 'Get item from the top of the stack (LIFO) topStack = stack.Pop() 'Result: "Smith" 'Clear the Stack stack.Clear Set stack = Nothing |