What I am doing is using a stream reader to read data from a file each line of the file contains 3 parts:
ToolCode,Description,Price
Obviously I am using the "," as the delimiter character
I would like to split up the three parts into three separate arrays. I have a textbox set up where the user inputs a toolcode (must match exactly) and i would like it to display the description and the price in separate textboxes. I know where my problem resides I just can't find anything that tells me how to define the variable properly.
This is the code for the Load Event:
VB Code:
'Declare variables and constants Dim strFileName As String Dim strLine As String Dim chrDelimiter As Char 'Declare delimiter character chrDelimiter = "," strFileName = CurDir() & "\tools.txt" Dim srdReadFile As System.IO.StreamReader = New System.IO.StreamReader(strFileName) Do Until srdReadFile.peek = -1 ReDim Preserve strToolCode(intNumTools) = strFields(0) 'I realize this is illegal but how do I define this so that I can display it later? ReDim Preserve strDescription(intNumTools) ReDim Preserve decPrices(intNumTools) strLine = srdReadFile.ReadLine strFields = strLine.Split(chrDelimiter) intNumTools = intNumTools + 1 Loop 'Close file FileClose()
This is the search button code:
VB Code:
'Declare variables Dim intCounter As Integer Dim intResults As Integer Dim strFindToolCode As String Dim blnFound As Boolean Dim intPartIndex As Integer Dim intNumRecords As Integer strFindToolCode = CStr(txtToolCode.Text) blnFound = False For intCounter = 0 To intNumTools - 1 If UCase(strFindToolCode) = UCase(strToolCode(intCounter)) Then blnFound = True intPartIndex = intCounter Exit For End If Next If blnFound Then txtDesc.Text = strToolCode(intPartIndex) Else MsgBox("Part not found", MsgBoxStyle.Exclamation, "Harry's Hardware") Exit Sub End If
My 3 textboxes are txtToolCode, txtDesc, and txtPrice




Reply With Quote