VB中如何利用驱动器列表框,目录列表框和文件列表框打开文本文件。

如题,VB中如何利用驱动器列表框,目录列表框和文件列表框打开文本文件。打开文件不是说直接用SHELL驱动,我是需要把TXT文件打开,放到一个文本框中修改,再保存到原文件中。
各位高手指点一下~~

窗体内画个drivelistbox dirlistbox和filelistbox 再放两个按钮 caption分别为打开 保存,再放一个文本框控件 multiline设为true scrollbar设成2
加入下面代码

Option Explicit

Private Sub Command1_Click() '打开文件
Dim FN As String
FN = Replace(File1.Path & "\" & File1.FileName, "\\", "\")
Text1 = OpenTxt(FN)
End Sub

Private Sub Command2_Click() '保存文件
Dim FN As String
FN = Replace(File1.Path & "\" & File1.FileName, "\\", "\")
Open FN For Output As #1
Print #1, Text1
Close #1
End Sub

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

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

Private Sub Form_Load()
File1.Pattern = "*.txt"
End Sub
Private Function OpenTxt(ByVal FN As String) As String

Open FN For Binary As #1
OpenTxt = Input(LOF(1), 1)
Close #1

End Function
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-11
我会弄,我弄过,用input语句
相似回答