我在这里学编程 进阶篇 共28页[1 2 3 4 5 6 7 >»<.. 最后一页]

文本文件浏览器

     我们用编制图形文件查看程序的方法来完成,所不同的是,这这个程序中使用了FileSystemObject对象的TextStream的中的OpenTextFile和ReadAll,程序运行界面如下:

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_DblClick()
Dim fs As New FileSystemObject
Dim txtf As TextStream
If Right(Dir1.Path, 1) = "\" Then
filename = Dir1.Path + File1.filename
Else
filename = Dir1.Path + "\" + File1.filename
End If
Set txtf = fs.OpenTextFile(filename)
If Not txtf.AtEndOfStream Then
tb.Text = txtf.ReadAll
End If
End Sub

Private Sub Form_Load()
'设置应用程序所在驱动器和目录为当前驱动器和目录
'App 是当前的应用程序对象
Drive1.Drive = App.Path
Dir1.Path = App.Path
File1.Pattern = "*.txt"
End Sub

我在这里学编程 进阶篇 共28页[1 2 3 4 5 6 7 >»<.. 最后一页]