Queue


BET_QueueItem class

Public Value As Variant 
Public NextItem As BET_QueueItem

Private Sub Class_Initialize()
   Set NextItem = Nothing
End Sub

Private Sub Class_Terminate()
   Set NextItem = Nothing
End Sub

BET_Queue class

Private _Front As BET_QueueItem 
Private _Rear As BET_QueueItem

Public Sub Add(NewItem As Variant)
Dim new_QItem As BET_QueueItem
   Set new_QItem = New BET_QueueItem
   new_QItem.Value = NewItem

   If (Me.Property_IsQueueEmpty() = True) Then
      Set Me._Front = new_QItem
      Set Me._Back = new_QItem
   Else
      Set Me._Rear.NextItem = new_QItem
      Set _Rear = new_QItem
   End If
End Sub

Public Function Remove() As Variant
   If (Me.Property_IsQueueEmpty() = True) Then
      Remove = Nothing
   Else
      Remove = _Front.Value
      If (_Front Is _Rear) Then
         Set _Front = Nothing
         Set _Rear = Nothing
      Else
        Set _Front = _Front.NextItem
      End If
   End If
End Function

Property Get Property_IsQueueEmpty() As Boolean
   Property_IsQueueEmpty = ( (_Front Is Nothing) And (_Back is Nothing) )
End Property

Private Sub Class_Initialize()
   Set NextItem = Nothing
End Sub

Sample

Public Sub Testing_Queue() 
Dim myQueue As BET_Queue
   myQueue = New BET_Queue
   myQueue.Add "Monday"
   myQueue.Add "Tuesday"
   myQueue.Add "Wednesday"
   myQueue.Add "Thursday"
   myQueue.Add "Friday"

  Do Until (myQueue.Property_IsQueueEmpty() = True)
   Debug.Print myQueue.Remove()
   Loop
End Sub

System.Collections.Queue

This does not work with Office 365.
This only works if you have .NET 3.5 installed.

Dim oQueue As Object 
Set oQueue = CreateObject("System.Collections.Queue")

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext