Showing posts with label queue. Show all posts
Showing posts with label queue. Show all posts

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

Monday, March 7, 2011

Visual basic arrays, arraylists, hashtables and queues.

Here are some examples of arrays, arraylists, hashtables, and queues. (From Teeps)

  Public Class frmJuke  
Dim strDahArray(0 To 2) As String
Dim arrTestMyList As New ArrayList
Dim hashTable As New Hashtable
Dim qQueue As New Queue
Private Sub btnAddCD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArray.Click
strDahArray(0) = "This is cool"
strDahArray(1) = "This is cooler"
strDahArray(2) = "This is the coolest"
For x As Integer = 0 To 2
MsgBox(strDahArray(x))
Next
lstArray.DataSource = strDahArray
cboArray.DataSource = strDahArray
End Sub
Private Sub btnArrayList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArrayList.Click
arrTestMyList.Add("this is not cool")
arrTestMyList.Add("not even this is cool")
arrTestMyList.Add("this sux")
For Each Str As String In arrTestMyList
MsgBox(Str)
Next
lstArray.DataSource = arrTestMyList
cboArray.DataSource = arrTestMyList
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
arrTestMyList.Clear()
For y As Integer = 0 To (strDahArray.Length - 1)
strDahArray(y) = ""
Next
lstArray.DataSource = Nothing
cboArray.DataSource = Nothing
End Sub
Private Sub btnAddToArrayList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddToArrayList.Click
arrTestMyList.Add(txtArrayList.Text)
txtArrayList.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
hashTable.Add("box1", "asdf")
hashTable.Add("box2", "jld;fkajdf;lasdf")
For Each obj As DictionaryEntry In hashTable
MsgBox(obj.Key & "=" & obj.Value)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim str As String
qQueue.Enqueue("third")
qQueue.Enqueue("second")
qQueue.Enqueue("first")
Do While qQueue.Count > 0
str = qQueue.Dequeue()
MsgBox(str)
Loop
End Sub
End Class