VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "cp_Stack_cls"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'IMPORTANT NOTE: The stack element 0 will always contain nothing (vbNullString)

Private vl_Stack_ast() As String
Private Const vl_IsInitialized_bln As Boolean = True

Public Sub Push(pr_Data_str As String)
Dim vl_Index_int As Integer

vl_Index_int = UBound(vl_Stack_ast)
vl_Stack_ast(vl_Index_int) = pr_Data_str
ReDim Preserve vl_Stack_ast(vl_Index_int + 1)


End Sub

Public Function Pop() As String
Dim vl_PoppedString_str As String
Dim vl_UBound_int As Integer

If vl_IsInitialized_bln = False Then
    Exit Function
End If

'Save the current uBound
vl_UBound_int = UBound(vl_Stack_ast)
'Save the highest value (ubound -1 because array is zero-length)
vl_PoppedString_str = vl_Stack_ast(vl_UBound_int - 1)
'Redim the array to exclude the topmost item
ReDim Preserve vl_Stack_ast(vl_UBound_int - 1)

Pop = vl_PoppedString_str
End Function

Private Sub Initialize()
ReDim vl_Stack_ast(0)
End Sub

Public Sub Clear(Optional pw_Count_int As Integer = 0)

If vl_IsInitialized_bln = False Then
    Exit Sub
End If

'If pr_count_int=0 then clear all, if there is a count then follow that count
'If there is no count specified,
If pr_Count_int = 0 Then
    'Clear the array
    Initialize
'Otherwise there is a count specified,
Else
    'Pop each item until the count has been reached
    Do Until pw_Count_int = 0
        Pop
        pw_Count_int = pw_Count_int - 1
    Loop
End If
End Sub

Public Function StackCount() As Integer

If vl_IsInitialized_bln = False Then
    Exit Function
End If


StackCount = UBound(vl_Stack_ast)
End Function

Public Function Trace(Optional pr_Delimeter_str As String = ">") As String
Dim vl_Counter_int As Integer
Dim vl_Data_str As String

'Iterate through each item in the stack
For vl_Counter_int = 0 To StackCount - 1
    'Append the current item name to the stack
    vl_Data_str = vl_Data_str & vl_Stack_ast(vl_Counter_int) & pr_Delimeter_str
Next vl_Counter_int
'Remove the final delimeter
vl_Data_str = Left(vl_Data_str, Len(vl_Data_str) - 1)
'Return
Trace = vl_Data_str
End Function

Private Sub Class_Initialize()
Initialize
End Sub
