Hi, please have a look at the following code.
When I use it on a module I get User-defined type not defined Error. at cs As New cStack
Code:
'class Module
Option Explicit
Dim pStack As Collection
Public Function Pop() As Variant
With pStack
If .Count > 0 Then
Pop = .Item(.Count)
.Remove .Count
End If
End With
End Function
Public Function Push(newItem As Variant) As Variant
With pStack
.Add newItem
Push = .Item(.Count)
End With
End Function
Public Sub init()
Set pStack = New Collection
End Sub
When I use it on a module I get User-defined type not defined Error. at cs As New cStack
Code:
Option Explicit
Sub test()
Dim [B]cs As New cStack[/B]
Dim i As Long
Set cs = New cStack
With cs
.init
For i = 1 To 10
Debug.Print CStr(.Push(i))
Next i
For i = 1 To 10
Debug.Print CStr(.Pop)
Next i
End With
End Sub