excel vba queue fifo memory structure first in first out
'VBA does not include a native QUEUE (FIFO: FIRST-In-FIRST-Out) memory
'structure. It is possible to implement AN a QUEUE using nothing but a native
'array or collection.
'However, the easiest solution is to have VBA create and use a .NET Queue:
Set Queue = CreateObject("System.Collections.Queue")
Queue.Enqueue "I"
Queue.Enqueue "was"
Queue.Enqueue "here."
MsgBox Queue.Dequeue '<--displays: I
'Note: Dequeue() removes the bottom (first-added) item from the Queue.
' Peek() will return the bottom value without removing it:
MsgBox Queue.Peek '<--displays: was
'Queue interrogation:
MsgBox Queue.Count '<--displays: 2. Count() returns 0 if Stack empty.
MsgBox Queue.Contains("I") '<--displays: False
'Queue to 1D VBA array (zero based):
arr = Queue.toArray
MsgBox arr(0) '<--displays: was Queue is unaltered.
'Clone the Queue:
Set Queue2 = Queue.Clone '<--Queue is not affected by ops on Stack.
'Empty the Queue:
Queue.Clear '<--Stack now empty, but can take a new Push().
'NB: Queues can hold simple values and also complex objects.
'Reference:
' https://docs.microsoft.com/en-us/dotnet/api/system.collections.queue
Are there any code examples left?
New code examples in category VBA
-
VBA 2022-03-27 20:55:02 excel vba check if all substrings in list are in string
-
VBA 2022-03-27 20:40:39 excel vba set cell value to empty
-
VBA 2022-03-27 17:05:52 vba simple quote
-
VBA 2022-03-27 14:30:19 textbox find and replace vb
-
VBA 2022-03-27 09:10:21 nested if else in vb.net
-
VBA 2022-03-27 09:10:09 excel vba string to bits
-
VBA 2022-03-25 02:00:15 vba verticalalignment
-
VBA 2022-03-24 12:20:06 Excel web scraping
-
VBA 2022-03-24 10:11:00 excel vba BitToLong
-
VBA 2022-03-21 18:00:05 excel vba save file txt