Public Class frmBaseball Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents lblProCode As System.Windows.Forms.Label Friend WithEvents lblManufacturer As System.Windows.Forms.Label Friend WithEvents txtProCode As System.Windows.Forms.TextBox Friend WithEvents txtManufacturer As System.Windows.Forms.TextBox Friend WithEvents lblDescription As System.Windows.Forms.Label Friend WithEvents lblPrice As System.Windows.Forms.Label Friend WithEvents txtDescription As System.Windows.Forms.TextBox Friend WithEvents txtPrice As System.Windows.Forms.TextBox Friend WithEvents lblCategory As System.Windows.Forms.Label Friend WithEvents txtCategory As System.Windows.Forms.TextBox Friend WithEvents lstMain As System.Windows.Forms.ListBox Friend WithEvents lblInfo As System.Windows.Forms.Label Friend WithEvents lstDisplay As System.Windows.Forms.ListBox Friend WithEvents lblDisplay As System.Windows.Forms.Label Friend WithEvents btnClear As System.Windows.Forms.Button Friend WithEvents btnExit As System.Windows.Forms.Button Friend WithEvents btnManDisplay As System.Windows.Forms.Button Friend WithEvents btnSearchProCode As System.Windows.Forms.Button Private Sub InitializeComponent() Me.lblProCode = New System.Windows.Forms.Label Me.lblManufacturer = New System.Windows.Forms.Label Me.txtProCode = New System.Windows.Forms.TextBox Me.txtManufacturer = New System.Windows.Forms.TextBox Me.lblDescription = New System.Windows.Forms.Label Me.lblPrice = New System.Windows.Forms.Label Me.txtDescription = New System.Windows.Forms.TextBox Me.txtPrice = New System.Windows.Forms.TextBox Me.lblCategory = New System.Windows.Forms.Label Me.txtCategory = New System.Windows.Forms.TextBox Me.lstMain = New System.Windows.Forms.ListBox Me.lblInfo = New System.Windows.Forms.Label Me.lstDisplay = New System.Windows.Forms.ListBox Me.lblDisplay = New System.Windows.Forms.Label Me.btnClear = New System.Windows.Forms.Button Me.btnExit = New System.Windows.Forms.Button Me.btnManDisplay = New System.Windows.Forms.Button Me.btnSearchProCode = New System.Windows.Forms.Button Me.SuspendLayout() ' 'lblProCode ' Me.lblProCode.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblProCode.Location = New System.Drawing.Point(16, 16) Me.lblProCode.Name = "lblProCode" Me.lblProCode.Size = New System.Drawing.Size(136, 24) Me.lblProCode.TabIndex = 0 Me.lblProCode.Text = "Product Code:" ' 'lblManufacturer ' Me.lblManufacturer.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblManufacturer.Location = New System.Drawing.Point(16, 48) Me.lblManufacturer.Name = "lblManufacturer" Me.lblManufacturer.Size = New System.Drawing.Size(144, 24) Me.lblManufacturer.TabIndex = 1 Me.lblManufacturer.Text = "Manufacturer:" ' 'txtProCode ' Me.txtProCode.Location = New System.Drawing.Point(152, 16) Me.txtProCode.Name = "txtProCode" Me.txtProCode.Size = New System.Drawing.Size(136, 20) Me.txtProCode.TabIndex = 2 Me.txtProCode.Text = "" ' 'txtManufacturer ' Me.txtManufacturer.Location = New System.Drawing.Point(152, 48) Me.txtManufacturer.Name = "txtManufacturer" Me.txtManufacturer.Size = New System.Drawing.Size(136, 20) Me.txtManufacturer.TabIndex = 3 Me.txtManufacturer.Text = "" ' 'lblDescription ' Me.lblDescription.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblDescription.Location = New System.Drawing.Point(304, 16) Me.lblDescription.Name = "lblDescription" Me.lblDescription.Size = New System.Drawing.Size(120, 24) Me.lblDescription.TabIndex = 4 Me.lblDescription.Text = "Description:" ' 'lblPrice ' Me.lblPrice.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblPrice.Location = New System.Drawing.Point(360, 48) Me.lblPrice.Name = "lblPrice" Me.lblPrice.Size = New System.Drawing.Size(64, 24) Me.lblPrice.TabIndex = 5 Me.lblPrice.Text = "Price:" ' 'txtDescription ' Me.txtDescription.Location = New System.Drawing.Point(416, 16) Me.txtDescription.Name = "txtDescription" Me.txtDescription.Size = New System.Drawing.Size(136, 20) Me.txtDescription.TabIndex = 6 Me.txtDescription.Text = "" ' 'txtPrice ' Me.txtPrice.Location = New System.Drawing.Point(416, 48) Me.txtPrice.Name = "txtPrice" Me.txtPrice.Size = New System.Drawing.Size(136, 20) Me.txtPrice.TabIndex = 7 Me.txtPrice.Text = "" ' 'lblCategory ' Me.lblCategory.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblCategory.Location = New System.Drawing.Point(568, 16) Me.lblCategory.Name = "lblCategory" Me.lblCategory.Size = New System.Drawing.Size(96, 24) Me.lblCategory.TabIndex = 8 Me.lblCategory.Text = "Category:" ' 'txtCategory ' Me.txtCategory.Location = New System.Drawing.Point(664, 16) Me.txtCategory.Name = "txtCategory" Me.txtCategory.Size = New System.Drawing.Size(136, 20) Me.txtCategory.TabIndex = 9 Me.txtCategory.Text = "" ' 'lstMain ' Me.lstMain.Location = New System.Drawing.Point(288, 80) Me.lstMain.Name = "lstMain" Me.lstMain.Size = New System.Drawing.Size(512, 147) Me.lstMain.TabIndex = 10 ' 'lblInfo ' Me.lblInfo.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblInfo.Location = New System.Drawing.Point(296, 240) Me.lblInfo.Name = "lblInfo" Me.lblInfo.Size = New System.Drawing.Size(504, 24) Me.lblInfo.TabIndex = 11 Me.lblInfo.Text = "Select an Item to Display It's Details!" Me.lblInfo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'lstDisplay ' Me.lstDisplay.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lstDisplay.ItemHeight = 18 Me.lstDisplay.Items.AddRange(New Object() {"Bats", "Gloves", "Gear"}) Me.lstDisplay.Location = New System.Drawing.Point(216, 88) Me.lstDisplay.Name = "lstDisplay" Me.lstDisplay.Size = New System.Drawing.Size(64, 58) Me.lstDisplay.TabIndex = 12 ' 'lblDisplay ' Me.lblDisplay.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblDisplay.Location = New System.Drawing.Point(16, 96) Me.lblDisplay.Name = "lblDisplay" Me.lblDisplay.Size = New System.Drawing.Size(200, 48) Me.lblDisplay.TabIndex = 13 Me.lblDisplay.Text = "Select a Category to Display All Item's" ' 'btnClear ' Me.btnClear.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnClear.Location = New System.Drawing.Point(192, 160) Me.btnClear.Name = "btnClear" Me.btnClear.Size = New System.Drawing.Size(88, 48) Me.btnClear.TabIndex = 14 Me.btnClear.Text = "Clear Form" ' 'btnExit ' Me.btnExit.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnExit.Location = New System.Drawing.Point(192, 216) Me.btnExit.Name = "btnExit" Me.btnExit.Size = New System.Drawing.Size(88, 48) Me.btnExit.TabIndex = 15 Me.btnExit.Text = "Exit" ' 'btnManDisplay ' Me.btnManDisplay.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnManDisplay.Location = New System.Drawing.Point(16, 160) Me.btnManDisplay.Name = "btnManDisplay" Me.btnManDisplay.Size = New System.Drawing.Size(152, 48) Me.btnManDisplay.TabIndex = 16 Me.btnManDisplay.Text = "Display Items for a Manufacturer" ' 'btnSearchProCode ' Me.btnSearchProCode.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnSearchProCode.Location = New System.Drawing.Point(16, 216) Me.btnSearchProCode.Name = "btnSearchProCode" Me.btnSearchProCode.Size = New System.Drawing.Size(152, 48) Me.btnSearchProCode.TabIndex = 17 Me.btnSearchProCode.Text = "Search for a Product Code" ' 'frmBaseball ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(808, 273) Me.Controls.Add(Me.btnSearchProCode) Me.Controls.Add(Me.btnManDisplay) Me.Controls.Add(Me.btnExit) Me.Controls.Add(Me.btnClear) Me.Controls.Add(Me.lblDisplay) Me.Controls.Add(Me.lstDisplay) Me.Controls.Add(Me.lblInfo) Me.Controls.Add(Me.lstMain) Me.Controls.Add(Me.txtCategory) Me.Controls.Add(Me.lblCategory) Me.Controls.Add(Me.txtPrice) Me.Controls.Add(Me.txtDescription) Me.Controls.Add(Me.lblPrice) Me.Controls.Add(Me.lblDescription) Me.Controls.Add(Me.txtManufacturer) Me.Controls.Add(Me.txtProCode) Me.Controls.Add(Me.lblManufacturer) Me.Controls.Add(Me.lblProCode) Me.Name = "frmBaseball" Me.Text = "Baseball, Etc." Me.ResumeLayout(False) End Sub #End Region Dim strProCode(), strManufacturer(), strDescription(), strCategory() As String, decPrice() As Decimal, intNumRecords As Integer Private Sub frmBaseball_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'declare variables (4) Dim strFileName As String Dim strLine As String Dim strFields() As String Dim chrDelimiter As Char 'Setup file info and delimiter (1)' strFileName = CurDir() & "\Baseball.txt" chrDelimiter = "," 'Initialize Counter (1) intNumRecords = 0 'Setup stringreader function (1)' Dim srdReadFile As System.IO.StreamReader = New System.IO.StreamReader(strFileName) 'Load program array from file (1)' Do Until srdReadFile.Peek = -1 'Resize the arrays (5)' ReDim Preserve strProCode(intNumRecords) ReDim Preserve strManufacturer(intNumRecords) ReDim Preserve strDescription(intNumRecords) ReDim Preserve strCategory(intNumRecords) ReDim Preserve decPrice(intNumRecords) 'read a line from the file (1)' strLine = srdReadFile.ReadLine 'Split line into its components. strFields is an array and is dynamic. Size does not matter here. No need for ReDim etc.(1)' strFields = strLine.Split(chrDelimiter) 'Put the elements into correct program arrays(5)' strProCode(intNumRecords) = strFields(0) strManufacturer(intNumRecords) = strFields(1) strDescription(intNumRecords) = strFields(2) strCategory(intNumRecords) = strFields(3) decPrice(intNumRecords) = strFields(4) 'increment counter(1)' intNumRecords = intNumRecords + 1 Loop 'Close file FileClose() End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click 'Exits the program (1)' End End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click 'Clear the text boxes (5)' txtProCode.Text = "" txtManufacturer.Text = "" txtDescription.Text = "" txtPrice.Text = "" txtCategory.Text = "" 'Clear the main lst box (1)' lstMain.Items.Clear() 'Sets the focus to the ProCode text box (1)' txtProCode.Focus() End Sub Private Sub btnManDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManDisplay.Click 'Decalre my variables' Dim strSearchString, strAManu, strSelected As String Dim blnFound As Boolean Dim intCounter, intNumber, intFoundIndex As Integer 'intialize the boolean to false' blnFound = False 'Verifiy that the user has entered something in the text box' If txtManufacturer.Text = "" Then txtManufacturer.Text = InputBox("Please enter a Manufacturer:", "Search String") Exit Sub End If strSearchString = txtManufacturer.Text 'Loop to search with. UCase converts both to upper case so case doesn't matter when entered' For Each strAManu In strManufacturer If InStr(strAManu, strSearchString) > 0 Then lstMain.Items.Add(strAManu) End If Next End Sub Private Sub btnSearchProCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchProCode.Click 'Decalre my variables' Dim strSearchString, strAProCode, strSelected As String Dim blnFound As Boolean Dim intCounter, intNumber, intFoundIndex As Integer 'intialize the boolean to false' blnFound = False 'Verifiy that the user has entered something in the text box' If txtProCode.Text = "" Then txtProCode.Text = InputBox("Please enter a Product Code:", "Search String") Exit Sub End If strSearchString = txtProCode.Text 'Loop to search with. UCase converts both to upper case so case doesn't matter when entered' For Each strAProCode In strProCode If InStr(strAProCode, strSearchString) > 0 Then lstMain.Items.Add(strAProCode) End If Next End Sub Private Sub lstMain_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstMain.SelectedIndexChanged 'declare counter variable, largest variable, and index value for largest check Dim intCount As Integer Dim strIndex, strAProCode, strAManu As String Dim intMaxIndex As Integer 'initialize largest variable and max index value' strIndex = strProCode(0) intMaxIndex = 0 'loop to search all checks and retain the largest For intCount = 0 To intNumRecords - 1 If strProCode(intCount) = lstMain.SelectedItem Then strIndex = strProCode(intCount) intMaxIndex = intCount End If Next intCount txtProCode.Text = strProCode(intMaxIndex) txtManufacturer.Text = strManufacturer(intMaxIndex) txtDescription.Text = strDescription(intMaxIndex) txtPrice.Text = decPrice(intMaxIndex) txtCategory.Text = strCategory(intMaxIndex) End Sub Private Sub lstDisplay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDisplay.SelectedIndexChanged Dim strSearchCat, strACat As String, blnFound As Boolean blnFound = False strSearchCat = lstDisplay.SelectedItem For Each strACat In strCategory If InStr(UCase(strACat), UCase(strSearchCat)) > 0 Then lstMain.Items.Add(strACat) blnFound = True End If Next End Sub End Class