Wednesday, March 30, 2011

Visual Basic Arrays Part 3 Queue and Hashtables

3. Create a form that will work as a printer queue. This form will have the following inputs:
a.Add the title and pages to a hashtable
b.Add the hashtable to a queue which is a class variable
c.Clear the title and set the pages back to one
Refresh the queue list.
d.When submitted the click event will do the following:
a.remove the next item in the queue
b.Refresh the queue list box



Public Class Form1
Dim qJobs As New Queue

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim list As New Hashtable
list.Add("Title", txtTitle.Text)
list.Add("Copies", NumericUpDown1.Value)
qJobs.Enqueue(list)
refreshjobs()
NumericUpDown1.Value = 1
txtTitle.Clear()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If qJobs.Count > 0 Then
qJobs.Dequeue()
End If
refreshjobs()
End Sub
Private Sub refreshjobs()
ListBox1.Items.Clear()
For Each h As Hashtable In qJobs
ListBox1.Items.Add(h.Item("Title") & h.Item("Copies"))

Next
End Sub

End Class

No comments:

Post a Comment