为什么我的代码总是搜索最后一条记录而不是我搜索的记录,就像这样8850338005909
。
这是文本文件中的代码示例数据:
8501045891528,2271,"亚当斯·CNDY大厅 HNYLMN100S/36",57.25,36.00,4822,1,100,101,465 8850338001604,2271,"亚当斯·CNDY大厅 HNYLMN100S/36",57.25,36.00,4822,1,100,101,465 8850338005909,2271,"亚当斯·CNDY大厅 HNYLMN100S/36",57.25,36.00,4822,1,100,101,465 8850338002519,2312,"CLRTS CNDY COOL MINT 40S/60",27.75,60.00,7049,1,100,101,465 8850338001000,2313,"ADAMS GUM CLRETSTWIN PK14GX2/1",66.50,1.00,4822,1,100,101,470 4804880224138,2315,"BGUIO OIL CKNG 16KG/1",978.00,1.00,6135,1,192,193,639
我的代码:
Private Sub Data2()
Dim text As String = IO.File.ReadAllText("C:\ITEMRTV.txt")
Dim index As Integer = text.IndexOf(TextBox1.Text)
Dim Values() As String = Split(text, ",")
If index >= 0 Then
' String is in file, starting at character "index"
Label1.Text = Values(0) ' now contains first column value,
Label2.Text = Values(1) ' contains second column, etc.
Label3.Text = Values(2)
Label4.Text = Values(3)
Label5.Text = Values(4)
Label6.Text = Values(5)
End If
End Sub