- This topic explains about, how to use QUEUE in VB programming.
- Tools needed: Button1 (Button1), Button2 (Button2), RichTextBox1 (RichTextBox1).
QUEUE – Using QUEUE in VB
- Queue is a particular kind of Abstract data type or collection. Queue works like First-In-First-Out Method, which means the item added first in the Queue is the item get out from the Queue. Addition of the item at the rear terminal position is known as enqueue, removal of the item from the fornt terminal position is known as dequeue.
Commonly using function:
Enqueue : Add an Item in Queue
Syntax : Stack.Enqueue(Object)
Object : The item to add in Queue
Dequeue : Remove the oldest item from Queue
Syntax : Stack.Dequeue()
Returns : Remove the oldest item and return.
Peek : Get the reference of the oldest item
Syntax : Stack.Peek()
returns : Get the reference of the oldest item in the Queue
Queue Class – Using QUEUE in VB
- Queue class represents a first-in, first-out collection of objects.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
- Syntax
|
1 2 3 4 5 |
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Class Queue _ Implements ICollection, IEnumerable, ICloneable |
Queue.Enqueue Method – Using QUEUE in VB
- Help to add an object to the end of the queue.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
- Syntax
|
1 2 3 4 |
'Declaration Public Overridable Sub Enqueue ( _ obj As Object _ ) |
Queue.Dequeue Method – Using QUEUE in VB
- Queue.Dequeue Method helps to remove the item at the beginning of the queue.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
- Syntax
|
1 2 |
'Declaration Public Overridable Function Dequeue As Object |
Queue.Contains Method – Using QUEUE in VB
- Helps to determine whether the item is present in the queue.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
- Syntax
|
1 2 3 4 |
'Declaration Public Overridable Function Contains ( _ obj As Object _ ) As Boolean |
Using QUEUE in VB – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Public Class Form1 'Declare an object for the queue Dim QueueList As New Queue Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click QueueList.Enqueue("Sunday") QueueList.Enqueue("Monday") QueueList.Enqueue("Tuesday") QueueList.Enqueue("Wednesday") QueueList.Enqueue("Thursday") QueueList.Enqueue("friday") QueueList.Enqueue("Saturday") While QueueList.Count > 0 RichTextBox1.Text = RichTextBox1.Text & QueueList.Dequeue() & vbNewLine End While End Sub End Class |
Using QUEUE in VB






