ok from what I see the file looks like this:
This should do the trick:Code:LastName FirstName CustomerNumber LastName FirstName CustomerNumber ...
VB Code:
Public Structure Customer Dim LastName As String Dim FirstName As String Dim CustomerNumber As String End Structure Public Function FindCustomer(ByRef CustomerInfo As Customer) As Boolean Dim sr As New System.IO.StreamReader("Database.txt") Dim strFile() As String = Split(sr.ReadToEnd, vbCrLf) Dim I As Integer For I = 0 To strFile.GetUpperBound(0) Step 3 ' Stepping 3 always makes sure we land on a last name If strFile(I).ToUpper = CustomerInfo.LastName.ToUpper Then CustomerInfo.FirstName = strFile(I + 1) CustomerInfo.CustomerNumber = strFile(I + 2) 'we found what we were looking for now lets not waste any time :D Return True End If Next End Function
now to use this:
VB Code:
'Put this in ur btnSearch's Click event Dim CustomerToFind As Customer CustomerToFind.LastName = InputBox("Please Type Customer Name: ", "Find Customer") If FindCustomer(CustomerToFind) = True Then 'We Found a Customer MsgBox(CustomerToFind.LastName & ", " & CustomerToFind.FirstName & " was Found!" & vbCrLf & _ "Customer Number: " & CustomerToFind.CustomerNumber, MsgBoxStyle.Information, "Customer Found!") Else MsgBox("Customer not Found!") End If





Reply With Quote