Posted By

heatherk on 02/22/10


Tagged

classes collections


Versions (?)

Integer Stack Class


 / Published in: Visual Basic
 

Wrapper class around a Collection object in VB6 to produce a stack for storing Integers.

  1. Option Explicit
  2. Private iColl As Collection
  3. Private curIndex As Integer
  4. Public Property Get TopValue() As Integer
  5. TopValue = iColl(curIndex)
  6. End Property
  7. Public Property Get Count() As Integer
  8. Count = curIndex
  9. End Property
  10.  
  11. Private Sub Class_Initialize()
  12. Set iColl = New Collection
  13. curIndex = 0
  14. End Sub
  15.  
  16. Public Sub Push(item As Integer)
  17. If curIndex = 0 Then
  18. iColl.Add item
  19. Else
  20. iColl.Add item, , , curIndex
  21. End If
  22. curIndex = curIndex + 1
  23. End Sub
  24.  
  25. Public Function Pop() As Integer
  26. Dim PoppedItem As Integer
  27. PoppedItem = iColl(curIndex)
  28. iColl.Remove curIndex
  29. curIndex = curIndex - 1
  30. Pop = PoppedItem
  31. End Function
  32. Public Sub Clear()
  33. Dim i As Integer
  34. Do Until iColl.Count = 0
  35. iColl.Remove curIndex
  36. curIndex = curIndex - 1
  37. Loop
  38. End Sub
  39. Private Sub Class_Terminate()
  40. Set iColl = Nothing
  41. End Sub

Report this snippet  

You need to login to post a comment.