'Purpose: Stack procedures 'VB Version: Excel 97 SR-1 'Written by: David Crawford ' Option Explicit ' 'Purpose: Checks if a stack array has items ' Public Function HasItems(StackArray As Variant) As Boolean If UBound(StackArray, 1) > 0 Then HasItems = True Else HasItems = False End If End Function ' 'Purpose: Adds items to a stack array ' Public Sub Push(StackArray As Variant, Value As Variant) On Error GoTo HandleErrors Dim LargestSubscript As Long LargestSubscript = UBound(StackArray, 1) ReDim Preserve StackArray(LargestSubscript + 1) StackArray(LargestSubscript + 1) = Value ExitProcedure: Exit Sub HandleErrors: 'if subscript error array is probably empty If Err = 9 Then 'add first element to array ReDim Preserve StackArray(0) StackArray(0) = Value Resume ExitProcedure 'else something else went wrong Else MsgErr "Push", Err Resume ExitProcedure End If End Sub ' 'Purpose: Returns and removes item for stack ' Public Function Pop(StackArray As Variant) As Variant Dim LargestSubscript As Long LargestSubscript = UBound(StackArray, 1) Pop = StackArray(LargestSubscript) ReDim Preserve StackArray(LargestSubscript - 1) End Function