Queues

user21009

Member
Joined
Aug 10, 2008
Messages
12
Programming Experience
Beginner
Hi

I'm a newbie to vb.net and I'm using vb.net 2005.
My problem is that I'm trying to write a program and I want to use a queue to save some messages and then display these messages in a label. Does anyone know how to do this?

Thanks in advance
 
Here is a sample of an object using a queue, in Form1 there are only two controls : Textbox1 and Button1.

VB.NET:
Public Class Form1
    Dim Myqueue As New Queue

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Myqueue.Enqueue("One")
        Myqueue.Enqueue("Two")
        Myqueue.Enqueue("Three")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Myqueue.Count > 0 Then
            TextBox1.Text = CStr(Myqueue.Dequeue)
        End If
    End Sub
End Class
 
Generics was added in .Net 2.0 for type safety and simplicity. If you intend to use it as a Queue for same type items use Queue(Of T) instead of the object Queue, in Bob Langlades example this would be Queue(Of String).
 
Back
Top