vb中如何对open语句的pathname 赋值?

来源:百度知道 编辑:UC知道 时间:2024/09/22 07:13:52
设计窗体“文件选择器”,编写适当的事件代码,要求运行后,驱动器、目录和文件列表框同步显示。并且文件列表框中显示相应路径下的文本文件,双击文件名时,在文本框中显示该文件的内容。
本人编的代码如下:
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_DblClick() '因为pathname是随机的,不知如何赋值?
Open “pathname” For Input As #1
Text1.Text = Input$(LOF(1), 1)
Close #1
End Sub

Private Sub Form_Load()
File1.Pattern = "*.txt"
End Sub
不知如何对编辑pathname?

dim pathname as string

'不是磁盘根目录的情况
pathname=file1.path & "\" & file1.filename

'磁盘根目录的情况
pathname=file1.path & file1.filename

我把这个事件过程给你重新写了一下,你试试
Private Sub File1_DblClick()
Dim PathName As String
PathName = File1.Path
PathName = PathName & IIf(Right(PathName, 1) = "\", "", "\") & File1.FileName
Open PathName For Input As #1
While Not EOF(1)
Line Input #1, S
s1 = s1 & S & IIf(EOF(1), "", vbCrLf)
Wend
Close #1
Text1.Text = s1
End Sub