Imports System.IO Public Class snowBoardBrandsForm Private Sub addBrandButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addBrandButton.Click, AddSnowBoardBrandToolStripMenuItem.Click Dim indexInteger As Integer Dim itemFound As Boolean Dim upperBrandTextString, upperListItemString As String itemFound = False indexInteger = 0 upperBrandTextString = brandComboBox.Text.ToUpper If brandComboBox.Text <> "" Then Do While Not itemFound And indexInteger < brandComboBox.Items.Count upperListItemString = brandComboBox.Items(indexInteger) upperListItemString = upperListItemString.ToUpper If upperBrandTextString = upperListItemString Then itemFound = True Else indexInteger += 1 End If Loop If itemFound Then MessageBox.Show("Brand is currently in the list", "Brand Match", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else brandComboBox.Items.Add(brandComboBox.Text) MessageBox.Show("Brand is added to the list", "Brand Added", MessageBoxButtons.OK, MessageBoxIcon.Information) End If brandComboBox.Text = "" brandComboBox.Focus() Else DisplayMessage("You must make an entry here", "Required Field") brandComboBox.Text = "" brandComboBox.Focus() End If End Sub Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click Me.Close() End Sub Private Sub SaveListToFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveListToFileToolStripMenuItem.Click Dim indexInteger, countInteger As Integer indexInteger = 0 countInteger = brandComboBox.Items.Count.ToString() If countInteger <> 0 Then Dim snowBoardBrandsStreamWriter As New StreamWriter("snowboardBrands.Txt") For indexInteger = 0 To countInteger - 1 Next indexInteger Else DisplayMessage("There are no items to be saved", "Entry Required") End If End Sub Private Sub DisplayMessage(ByVal errormsg As String, ByVal Titlebar As String) MessageBox.Show(errormsg, Titlebar, MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub Private Sub RemoveSnowboardBrandToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveSnowboardBrandToolStripMenuItem.Click brandComboBox.Items.RemoveAt(brandComboBox.SelectedItem) End Sub Private Sub ClearTheListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearTheListToolStripMenuItem.Click Dim returnDialogResult As DialogResult returnDialogResult = MessageBox.Show("Do you want to clear the brand list?", "Clear List?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If returnDialogResult = Windows.Forms.DialogResult.Yes Then brandComboBox.Items.Clear() End If End Sub Private Sub DisplayNumberOfSnowboardBrandsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayNumberOfSnowboardBrandsToolStripMenuItem.Click Dim numberBrands As Integer Dim messageString As String numberBrands = brandComboBox.Items.Count.ToString messageString = "Total Number of Brands: " & numberBrands.ToString MessageBox.Show(messageString, "Snowboard Brands", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click 'AboutBox1.ShowDialog() End Sub Private Sub snowBoardBrandsForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim brandString As String Try Dim snowboardBrandsStreamReader As New StreamReader("SnowboardBrand.Txt") Do While snowboardBrandsStreamReader.Peek <> -1 brandString = snowboardBrandsStreamReader.ReadLine() brandComboBox.Items.Add(brandString) Loop Catch ex As Exception DisplayMessage("The file SnowboardBrands.Txt will be created.", "File was not found") End Try End Sub Private Sub snowBoardBrandsForm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing Dim numberBrands As Integer numberBrands = brandComboBox.Items.Count If numberBrands = 0 Then File.Delete("SnowboardBrand.Txt") Else End If End Sub End Class