在开发过程中,驱动器列表框名为Drive1,目录列表框名为Dirl,文件列表框名为File1,目标字符串输入框名为Text1,“查找”按钮名为Command1。 [Visual Basic 代码] Private Sub Drivel_Change() Dirl. Path= (1) ’更新目录列表框的路径 End Sub Private Sub Dirl_Change( ) (2) = Dirl. Path ’更新文件列表框的路径 End Sub Private Sub Commandl_Click( ) Dim fso, a As Object Dim i, j As Integer If (3) = "" Then ’判断是否已经选中某个文件 MsgBox "请选择一个文件文件!" (4) ’退出事件过程 End If ’创建文件系统对象以及文本流对象 Set fso = CreateOhjecl( "Scripting. FileSystemOhject" ) Set a = fso. OpenTextFile( Dirl. Path & "/" & (3) ) i=1 Do While (5) <> True ’逐行读取文件,直至文件末尾 strLine = a. ReadLine j = InStr(1, (6) )’返回目标字符串在文件这一行中的位置 If j > 0 Then ’如果目标字符串在这一行出现,则返回其位置 MsgBox "字符串第一次出现的位置是" & "(" & i & "," &j & "),," (4) ’退出事件过程 End If i:i+l Loop MsgBox "字符串在文件中不出现," End Sub