vb,请教

来源:百度知道 编辑:UC知道 时间:2024/05/22 08:48:19
我已经有一段代码:
Private Sub Command1_Click()
Dim r As String, s() As String, i As Long, x As Long
Open "123.txt" For Input As #1
Do Until EOF(1)
Line Input #1, r
If Len(r) > 0 Then
s = Split(r, ",")
If s(0) = Text1.Text Then
Form1.Label1.Caption = s(0)
Form1.Label2.Caption = s(1)
Form1.Label3.Caption = s(2)
Form1.List1.Clear
x = 0
For i = 3 To Val(s(2)) + 2
x = x + 1
Form1.List1.AddItem x & "." & "20" & Mid(s(i), 1, 2) & "." & Mid(s(i), 3, 2) & "." & Mid(s(i), 5, 2)
Next i
Unload Me
Exit Do
End If
End If
Loop
Close #1
End Sub

在哪里加什么代码能让它如果文件已经读完,且没有匹配的值的话msgbox "无此名单"并退出循环,关闭#1
搜索到的内容是第1行的话就没问题,第2、3、4……行的话即使搜索到了也显示无此名单啊

Private Sub Command1_Click()
Dim r As String, s() As String, i As Long, x As Long, blntest As Boolean
Open "123.txt" For Input As #1
Do Until EOF(1)
Line Input #1, r
If Len(r) > 0 Then
s = Split(r, ",")
If s(0) = Text1.Text Then
Form1.Label1.Caption = s(0)
Form1.Label2.Caption = s(1)
Form1.Label3.Caption = s(2)
Form1.List1.Clear
x = 0
For i = 3 To Val(s(2)) + 2
x = x + 1
Form1.List1.AddItem x & "." & "20" & Mid(s(i), 1, 2) & "." & Mid(s(i), 3, 2) & "." & Mid(s(i), 5, 2)
Next i
blntest = True
Exit Do
Else
blntest = False
End If
End If
Loop
If blntest = False Then MsgBox "无此名单"
Close #1
End Sub