可以改为:
1、form1窗体:
Option Explicit
Private L As New Stu
Private Sub Command1_Click()
If Option1.Value = True Then
ElseIf Option2.Value = True Then
If L.Name(Text2) = True Then
Text1.Text = L.StName
MsgBox "已经查找到!"
Else
Text1.Text = ""
MsgBox "查找失败!"
End If
End If
End Sub
2、定义一个类Stu:
Option Explicit
Public StName As String
Public Num As String
Public Addr As String
Public Tel As String
Public Function Name(ByVal Value As String) As Boolean
Dim A As String
Dim i As Integer
Dim IfLookFor As Boolean
A = Value
IfLookFor = False
Open "c:\stu_list" For Input As #1
For i = 1 To 2
Input #1, StName, Num, Addr, Tel
If A = StName Then
IfLookFor = True
Exit For
End If
Next i
Close #1
Name = IfLookFor
End Function