C盘根目录下stu.txt文件中以下的格式保存着学生姓名及班号信息。本程序的功能是:读取该文件中的数据,再利用InputvBox输入要查找的学生姓名,通过顺序查找,给出找到或找不到的信息。附图是某同学被找到时显示的信息窗口。
Option Explicit
Option Base 1
Private Sub Form_click()
Dim stu() As String, glass() As String, i As Integer
Dim n As Integer, name As String, k As Integer
Open "c:\stu\stu.txt" For Input As #11
Do While (1)
(2)
ReDim Preserve stu(n), glass(n)
Input #11, stu(n), glass(n)
Loop
name = InputBox("输入欲查找的学生姓名:")
Call search(name, stu, k)
If k <= n Then
MsgBox (3)
Else
MsgBox "无此人。"
End If
Close #11
End Sub
Private Sub search(name As String, stu() As String, k As Integer)
Dim i As Integer
For i = 1 To UBound(stu)
If name = stu(i) Then
(4)
End If
Next i
(5)
End Sub