473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

simple queue

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!!

Apr 11 '06 #1
4 1336
aa*********@gmail.com wrote:
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!!


There is a Queue collection type that may do what you want.

Chris
Apr 11 '06 #2
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!!

Apr 11 '06 #3
Aaron,

You mean something as an Listbox or whatever in what you deleteAt index 1
forever the first row as the total amount of rows is greather than 19 and
remove at (0) and add the latest everytime at the end

http://msdn.microsoft.com/library/de...oveattopic.asp

There are more controls with which you can do this.

If it has to be a kind of array, than I would use the ArrayList. In my
opinion is the (by me very much liked) queue class not the right one for
this because it is more to take and put objects automaticly in the queue and
not to show the items of that queue.

I hope this helps,

Cor

<aa*********@gmail.com> schreef in bericht
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!!

Apr 11 '06 #4
hey

thanks so much guys; i'm kinda new to the whole .NET world; i just CANT
BELIEVE HOW FAST THIS STUFF RUNS!!!
(i'm an olap dba who also dabbles in all this newfangled programming
stuff)

that listbox method might be EXACTLY what i was looking for; i'm going
to toy around with that.
it just seems a LOT easier (and i assume faster) that all this EnQ and
DeQ and iterating through stuff.

Thanks a lot; i am really going to dive into this tonight on the bus

my current, functional version.
It works pretty well; i can just tell it's running a little bit slower
than i want.
Should i just change the AppendText method to a stringbuilder??

Or is a listbox.objectcollection.removeAt going to be faster and
simpler??

Dim Q As New Queue(Of String)
Public Sub WriteStatus(ByVal strStatus As String)
Dim strWaste As String
Dim I As Int16

Q.Enqueue(strStatus)
If Q.Count > 15 Then
strWaste = Q.Dequeue()
End If

Me.txtStatus.Clear()
I = 0

For Each strMessage As String In Q
Select Case I
Case 0
txtStatus.AppendText(strMessage)
Case Else
txtStatus.AppendText(vbCrLf & strMessage)
End Select
I = +1
Next
End Sub

Apr 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
16
by: Paul Rubin | last post by:
I'd like to have a function (or other callable object) that returns 0, 1, 2, etc. on repeated calls. That is: print f() # prints 0 print f() # prints 1 print f() # prints 2 # etc. ...
3
by: Kceiw | last post by:
Dear all, When I use #include "queue.h", I can't link it. The error message follows: Linking... G:\Projects\Datastructure\Queue\Debug\main.o(.text+0x136): In function `main':...
2
by: PiotrKolodziej | last post by:
Hi I have an event that receives data from RS port rs.DataReceived += new SerialDataReceivedEventHandler(rs_DataReceived); I need to block raising an event when the previous one has not lelft...
4
by: j_depp_99 | last post by:
Thanks to those guys who helped me out yesterday. I have one more problem; my print function for the queue program doesnt work and goes into an endless loop. Also I am unable to calculate the...
15
by: Bjoern Schliessmann | last post by:
Hello all, I'm trying to simulate simple electric logic (asynchronous) circuits. By "simple" I mean that I only want to know if I have "current" or "no current" (it's quite digital) and the only...
3
by: writser | last post by:
hey all, For my study I'm writing a simple threaded webcrawler and I am trying to do this in python. But somehow, using threads causes IDLE to crash on Windows XP (with the latest python...
10
by: blaine | last post by:
Hey everyone! I'm not very good with Tk, and I am using a very simple canvas to draw some pictures (this relates to that nokia screen emulator I had a post about a few days ago). Anyway, all is...
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.