1

As the title says, I am getting errors when trying to push an object onto a stack. I've attached the classes and tester code below:

Tester:

Sub stackTest()
    Dim stackTest As cStack
    Dim testCollection As Collection

    Set stackTest = New cStack
    stackTest.init

    Set tester = New Collection
    Set curObj = New DVObject

    'curObj.Value = "hmm"
    tester.Add Item:=curObj
    stackTest.Push (curObj)

    curObj.Value = "nope"

    Debug.Print (Stack.Pop)

End Sub

Stack:

Option Explicit
Public pStack As Collection

' get item from stack.
Public Function Pop() As Variant
    With pStack
        If .Count > 0 Then
            If IsObject(.Item(.Count)) Then
                Set Pop = .Item(.Count)
            Else
                Pop = .Item(.Count)
            End If
            Pop = .Item(.Count)
            .Remove .Count
        End If
    End With
End Function

' add item to stack.
Public Sub Push(newItem As Variant)
    pStack.Add Item:=newItem
End Sub

' check if stack is empty.
Public Function isEmpty() As Boolean
    If pStack.Count = 0 Then isEmpty = True Else isEmpty = False
End Function

' initialize the stack.
Public Sub init()
    Set pStack = New Collection
End Sub

DVObject:

Option Explicit

Public name As Variant
Public Value As Variant
Public parent As DVObject
Public firstChild As DVObject
Public nextSibling As DVObject

I get the error on the line in the tester "stackTest.Push (curObj)"

This is weird because it seems to me like it should work based on the previous line where I add it to a tester collection.

I've tried changing the Push method in the cStack class to

Public Sub Push(ByVal newItem As Variant)
Public Sub Push(ByVal newItem As DVObject)
Public Sub Push(newItem As DVObject)

but nothing seems to be working. Can anyone point out my mistake? I've spent quite a while trying to fix this.

I've got very large text files (~500 gb) that I need to parse through. The stack is going to help me figure out what code blocks I am in.

Jerm
  • 59
  • 7

0 Answers0