我已经分隔了一个文本文件并将其放入一个2D数组中。然后,我试图找出数组是否包含产品ID(在文本框中输入)。但是,我用来尝试搜索数组并显示名称的代码不起作用。 文本文件说: 1,弗朗西斯 2,艾玛
这是我的代码:
Public Class Form1
Dim filename As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
filename = "names.txt"
End Sub
Private Sub btnsearch_Click(sender As Object, e As EventArgs) Handles btnsearch.Click
filename = "names.txt"
FileOpen(1, filename, OpenMode.Input,,,)
Dim lines() As String = IO.File.ReadAllLines("names.txt")
Dim values(lines.Length - 1, 1) As String
For i As Integer = 0 To lines.Length - 1
Dim parts() As String = lines(i).Split(","c)
values(i, 0) = parts(0)
values(i, 1) = parts(1)
Next
Dim ID As String
ID = txtidsearch.Text
Dim line As String
Do While Not EOF(1)
line = LineInput(1)
If values().Contains(ID) Then
lblid.Text = line
Application.DoEvents()
GoTo line1
ElseIf EOF(1) = True
MsgBox("Not Found")
End If
Loop
line1:
FileClose(1)
End Sub
End Class
提前致谢
答案 0 :(得分:1)