我是 Visual Basic 2010 的新手,我一直在用这个把头撞到墙上。
我有一个接受用户输入并将其保存到以下格式的文本文件的表单:
“客户编号:”00
能源部,约翰
10350 某街
城市,州邮政编码
电话号码
"账户余额:$" 00.00
“最后付款日期:”月/日/年
我有一个文本框,用户根据选中的复选框输入客户编号或姓氏。这样做的目的是通过姓氏或客户编号在文本文件中搜索客户记录。
搜索时,我希望在列表框中显示搜索中使用的姓氏或客户编号的客户。
这是我下面的代码:
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
'Local Variables
Dim ReadCustomerRecords As StreamReader
Dim strCustomerNumber As String
' Validate Search Criteria
If chkCustomerNumber.Checked = False And chkLastName.Checked = False Then
MessageBox.Show("Please select either Customer Number OR Last Name" & vbNewLine & "to narrow your search.", "Attention")
End If
If chkCustomerNumber.Checked And chkLastName.Checked Then
MessageBox.Show("You may only search by Customer Number OR Last Name." & vbNewLine & "Please revise your search.", "Attention")
End If
If chkCustomerNumber.Checked Then
ReadCustomerRecords = File.OpenText(strCustomerRecordsFile)
strCustomerNumber = ReadCustomerRecords.ReadLine()
Do Until strCustomerRecordsFile.Contains(txtSearchFile.Text)
If strCustomerNumber.Contains(txtSearchFile.Text) Then
lstCustomerSearch.Items.Add(strCustomerNumber)
lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
Else
MessageBox.Show("The customer number you entered is not valid." & vbNewLine & "Please try again or search by Last Name.", "Attention")
End If
Return
Loop
ReadCustomerRecords.Close()
End If
If chkLastName.Checked Then
ReadCustomerRecords = File.OpenText(strCustomerRecordsFile)
End If
End Sub