simple queue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aaron.kempf@gmail.com

    #1

    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.WriteLi ne(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!!

  • Chris

    #2
    Re: simple queue

    aaron.kempf@gma il.com wrote:[color=blue]
    > 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.WriteLi ne(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!!
    >[/color]

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

    Chris

    Comment

    • Stephany Young

      #3
      Re: simple queue

      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.WriteLi ne(_s.Pop())
      Console.WriteLi ne(_s.Pop())
      ...
      Console.WriteLi ne(_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("Sta tus Message 1")
      _q.Enqueue("Sta tus Message 2")
      ...
      _q.Enqueue("Sta tus Message 10")

      Console.WriteLi ne(_q.Dequeue() )
      Console.WriteLi ne(_q.Dequeue() )
      ...
      Console.WriteLi ne(_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("Nex t 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.WriteLi ne(_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.WriteLi ne(_a(_i))
      Next


      <aaron.kempf@gm ail.com> wrote in message
      news:1144717626 .281047.51050@j 33g2000cwa.goog legroups.com...[color=blue]
      >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.WriteLi ne(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!!
      >[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: simple queue

        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



        <aaron.kempf@gm ail.com> schreef in bericht
        news:1144717626 .281047.51050@j 33g2000cwa.goog legroups.com...[color=blue]
        >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.WriteLi ne(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!!
        >[/color]


        Comment

        • aaron.kempf@gmail.com

          #5
          Re: simple queue

          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.objectc ollection.remov eAt going to be faster and
          simpler??

          Dim Q As New Queue(Of String)


          Public Sub WriteStatus(ByV al strStatus As String)
          Dim strWaste As String
          Dim I As Int16

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

          Me.txtStatus.Cl ear()
          I = 0

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

          Comment

          Working...