the problem i m facing now is, no matter what customer id i key in, the program still return "not in file" even there is such record in the text file!
thx for helping....
CODE
Structure Details
Dim custID, lastName, firstName, add1, add2, state, city, email As String
Dim icNo, zip, mobile, home, office As String
End Structure
Dim id(27) As Details
Private Sub search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As IO.StreamReader = IO.File.OpenText("d:\data\cust.txt")
For i As Integer = 0 To 27
id(i).custID = sr.ReadLine
id(i).icNo = sr.ReadLine
id(i).lastName = sr.ReadLine
id(i).firstName = sr.ReadLine
id(i).add1 = sr.ReadLine
id(i).add2 = sr.ReadLine
id(i).zip = sr.ReadLine
id(i).state = sr.ReadLine
id(i).city = sr.ReadLine
id(i).office = sr.ReadLine
id(i).mobile = sr.ReadLine
id(i).home = sr.ReadLine
id(i).email = sr.ReadLine
Next
sr.Close()
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim searchID As String, result As String
searchID = txt_searchID.Text.ToUpper
result = FindID(searchID)
If result >= 0 Then
ShowData(result)
Else
MsgBox(searchID & " not in file", 0, "Not Found")
End If
End Sub
Function FindID(ByVal searchID As String) As Integer
'Binary search table for customer id
Dim first, middle, last As Integer
first = 0
last = 27
Do While (first <= last)
middle = CInt(Int((first + last) / 2))
Select Case id(middle).custID.ToUpper
Case searchID
Return middle
Case Is > searchID
last = middle - 1
Case Is < searchID
first = middle + 1
End Select
Loop
Return -1
End Function
Sub ShowData(ByVal result As Integer)
txt_custID.Text = id(result).custID
txt_icNo.Text = id(result).icNo
txt_lastName.Text = id(result).lastName
txt_1stName.Text = id(result).firstName
txt_add1.Text = id(result).add1
txt_add2.Text = id(result).add2
txt_zip.Text = id(result).zip
txt_state.Text = id(result).state
txt_city.Text = id(result).city
txt_office.Text = id(result).office
txt_mobile.Text = id(result).mobile
txt_home.Text = id(result).home
txt_email.Text = id(result).email
End Sub
This post has been edited by danferd: 10 Mar, 2007 - 02:49 AM