All pastes #1511287 Raw Edit

[phear]crippler

public text v1 · immutable
#1511287 ·published 2009-07-29 17:49 UTC
rendered paste body
Public Class BandForm
    'Class level variables
    'The Collection Array
    Private bandStrings As String() = {"Gojira", _
                                       "Lamb of God", _
                                       "Black Flag", _
                                       "Slayer", _
                                       "Morbid Angel", _
                                       "Deicide", _
                                       "NOFX", _
                                       "The Misfits", _
                                       "1349", _
                                       "Dimmu Birgir", _
                                       "Amon Amarth", _
                                       "Old Mans Child", _
                                       "Pantera", _
                                       "Bane", _
                                       "Modern Life Is War", _
                                       "All Shall Perish", _
                                       "Job For A Cowboy", _
                                       "Beneath The Massacre", _
                                       "Behemoth", _
                                       "Black Sabbath"}
    'Create private collection variables for it's properties.
    Private listTypeString As String
    Private indexInteger As Integer
    'Create instances of these objects for security purposes.
    Private aSortedList As SortedList
    Private aHashTabel As Hashtable
    Private aStack As Stack
    Private aQueue As Queue
    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub
    Private Sub BandForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With Me
            .collectionClassComboBox.SelectedIndex = 0
            .Timer.Start()
            .dateToolStripStatusLabel.Text = Today.ToShortDateString
            .timeToolStripStatusLabel.Text = Now.ToLongTimeString
        End With
    End Sub
    Private Sub collectionClassComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles collectionClassComboBox.SelectedIndexChanged
        'Create a new collection based on the slected collection type.
        indexInteger = 0
        bandListBox.Items.Clear()
        listTypeString = collectionClassComboBox.SelectedItem.ToString
        Select Case listTypeString
            Case "Original"
                displayOriginal()
            Case "Hashtable"
                aHashTabel = New Hashtable()
            Case "Stack"
                aStack = New Stack()
            Case "Queue"
                aQueue = New Queue()
            Case "Sorted List"
                aSortedList = New SortedList()
        End Select
    End Sub
    Private Sub displayOriginal()
        Dim itemString As String
        'Display the array in its original Order.
        bandListBox.Items.Clear()
        For Each itemString In bandStrings
            bandListBox.Items.Add(itemString)
        Next
    End Sub
    Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
        Dim keyString As String
        Dim itemString As String
        'Add the next element to the slected collection.
        If indexInteger <= bandStrings.GetUpperBound(0) Then 'End Of Array...
            itemString = bandStrings(indexInteger) 'Connects to itemString...
            Try
                Select Case listTypeString
                    Case "Original"
                        MessageBox.Show("Cannot add to the original list.", "Band Collection", _
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Case "Hashtable"
                        keyString = itemString.GetHashCode.ToString
                        aHashTabel.Add(keyString, itemString)
                        'Reload the list from the hash table collection.
                        bandListBox.Items.Clear()
                        For Each itemString In aHashTabel.Values
                            bandListBox.Items.Add(itemString)
                        Next
                    Case "Stack"
                        aStack.Push(itemString)
                        'Reload the list from the stack.
                        bandListBox.Items.Clear()
                        For Each itemString In aStack
                            bandListBox.Items.Add(itemString)
                        Next
                    Case "Queue"
                        aQueue.Enqueue(itemString)
                        'Reload the list from the queue.
                        bandListBox.Items.Clear()
                        For Each itemString In aQueue
                            bandListBox.Items.Add(itemString)
                        Next
                    Case "Sorted List"

                        keyString = itemString.Substring(0, 3)
                        aSortedList.Add(keyString, itemString)
                        'Reload the list from the sorted list collection.
                        bandListBox.Items.Clear()
                        For Each itemString In aSortedList.Values
                            bandListBox.Items.Add(itemString)
                        Next
                        indexInteger += 1 'Move to the next array element.
                End Select
            Catch adding_err As Exception
                MessageBox.Show("Your computer has a problem." _
                                & ControlChars.NewLine _
                                & "It said: " & adding_err.Message, "Computer problem!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End Try
        Else
            MessageBox.Show("No more items for the list.", "Favorite Bands", _
                            MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
    Private Sub removeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles removeButton.Click
        Dim keyString As String
        Dim itemString As String
        'Remove an item from the collection.
        Try
            Select Case listTypeString
                Case "Original"
                    MessageBox.Show("Cannot remove from the original list.")
                Case "Hashtable"
                    If bandListBox.SelectedIndex <> -1 Then
                        itemString = bandListBox.SelectedItem.ToString
                        keyString = itemString.GetHashCode.ToString
                        aHashTabel.Remove(keyString)
                        'Reload the list from the has table collection.
                        bandListBox.Items.Clear()
                        For Each itemString In aHashTabel.Values
                            bandListBox.Items.Add(itemString)
                        Next
                    Else
                        MessageBox.Show("Select and item to remove.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Case "Stack"
                    aStack.Pop()
                    'Reload the list from the stack.
                    bandListBox.Items.Clear()
                    For Each itemString In aStack
                        bandListBox.Items.Add(itemString)
                    Next
                Case "Queue:"
                    aQueue.Dequeue()
                    'Reload the list from the stack
                    bandListBox.Items.Clear()
                    For Each itemString In aQueue
                        bandListBox.Items.Add(itemString)
                    Next
                Case "Sorted List"
                    If bandListBox.SelectedIndex <> -1 Then
                        itemString = bandListBox.SelectedItem.ToString
                        keyString = itemString.Substring(0, 3)
                        aSortedList.Remove(keyString)
                        'Reload the list fromt e sorted list collection.
                        bandListBox.Items.Clear()
                        For Each itemString In aSortedList.Values
                            bandListBox.Items.Add(itemString)
                        Next
                    Else
                        MessageBox.Show("Selected the item to remove.", "Hey...", MessageBoxButtons.OK, MessageBoxIcon.Hand)
                    End If
            End Select
        Catch removing_err As Exception
            MessageBox.Show("Your computer has a problem." _
                                & ControlChars.NewLine _
                                & "It said: " & removing_err.Message, "Computer problem!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub
    Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
        With Me
            .dateToolStripStatusLabel.Text = Today.ToShortDateString
            .timeToolStripStatusLabel.Text = Now.ToLongTimeString
        End With
    End Sub
End Class