It all depends on how you want to interrogate the 'queue'.
A Stack object is LIFO (Last In - First Out) and controlling the number of
entries in the stack is not a trivial exercise. Also when you 'pop' a value
from the stack, the value is removed from the stack.
Example:
Dim _s As New Stack()
_s.Push("Status Message 1")
_s.Push("Status Message 2")
...
_s.Push("Status Message 10")
Console.WriteLine(_s.Pop())
Console.WriteLine(_s.Pop())
...
Console.WriteLine(_s.Pop())
Gives:
Status Message 10
...
Status Message 2
Status Message 1
and the stack is now empty.
A Queue object is FIFO (First In - First Out) and controlling the number of
entries in the queue is musch easier. Also when you 'dequeue' a value from
the queue, the value is removed from the stack.
Dim _q As New Queue()
_q.Enqueue("Status Message 1")
_q.Enqueue("Status Message 2")
...
_q.Enqueue("Status Message 10")
Console.WriteLine(_q.Dequeue())
Console.WriteLine(_q.Dequeue())
...
Console.WriteLine(_q.Dequeue())
Gives:
Status Message 1
Status Message 2
...
Status Message 10
and the queue is now empty.
To control the number of entries:
If _q.Count = 20 then
'Dequeue the oldest entry and dump it
_q.Dequeue()
End If
_q.Enqueue("Next Status Message")
If you want to repeatedly the most recent 20 (or up to the most recent 20
rentries), I would be inclined to simply use an ArrayList object and control
the count.
Dim _a As New Queue()
_a.Add("Status Message 1")
_a.Add("Status Message 2")
...
_a.Add("Status Message 10")
For _i = 0 to _a.Count - 1
Console.WriteLine(_a(_i))
Next
Gives:
Status Message 1
Status Message 2
...
Status Message 10
and the entries are still in the arraylist.
To control the number of entries:
If _a.Count = 20 then
'Remove the oldest entry
_a.RemoveAt(0)
End If
_a.Add("Next Status Message")
If you want to read the arraylist from most recent to oldset, simply reverse
the order of the loop:
For _i = _a.Count - 1 to 0 Step -1
Console.WriteLine(_a(_i))
Next
<aa*********@gmail.com> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
i need a status box on my etl tool-- where i can 'trap' the 20 most
recent status messages.
i don't want to do a whole bunch of parsing of text; and string concat.
Dim s As New Stack()
s.Push("This")
s.Push("Is")
s.Push("How")
s.Push("Stacks")
s.Push("Work")
Console.WriteLine(s.Peek())
i saw this example; this is awfully similiar to what i want to do--
would it be crazy to make 20 different stacks
stack20->stack19->stack18->
i just dont get it; and i would LOVE a little bit of guidance.
i want to be able to push
Aaron
Matt
Ray
and then add a new member 'Jose'
which would give me
Jose
Aaron
Matt
thanks team!!