vb打开路径并选择

D:\vb\3.txt
这个是我text1里面的内容。我想通过双击text1实现打开D:\vb\并选择着3.txt。text1里面的内容是自动获取的。随时会变动的。打开后如图

第1个回答  2014-06-03
Option Explicit

Public m As Integer

Private Sub Command1_Click()

Dim txtTemp
Dim Textline As String
m = 1
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' 设置标志
CommonDialog1.Flags = cdlOFNHideReadOnly
' 设置过滤器
CommonDialog1.Filter = "TEXT Files (*.txt)|*.txt"
' 指定缺省的过滤器
CommonDialog1.FilterIndex = 2
' 显示“打开”对话框
CommonDialog1.ShowOpen
' 显示选定文件的名字
    Open CommonDialog1.FileName For Input As #1   ' 打开配置文件。
        Do While Not EOF(1)
            Line Input #1, Textline
            If Trim(Textline & " ") <> "" Then
                txtTemp = txtTemp & "|" & Textline
                List1.AddItem Textline
                
            End If

        Loop
    Close #1

ErrHandler:
End Sub


追问

我要的不是这个。。。比如你打开任务管理器。在程序上右键-打开所在位置。他会自动跳转到那个程序路径下。并选择那个文件。

追答

可不可以这样子的

CommonDialog1.InitDir = "D:\vb\"
CommonDialog1.FileName = Text1.Text
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1

追问

我不是要选择哪个文件。是要调用资源管理器打开对应的位置。选中。

追答

好吧 我还是不理解 无能为力了

第2个回答  2014-06-03
双击事件中写下面代码:
Dim fname As String = "D:\vb\3.txt"
Dim fs As New IO.FileStream(fname, IO.FileMode.Open)
Dim sr As New IO.StreamReader(fs)
TextBox1.Text = sr.ReadToEnd
fs.Close()
sr.Close()追问

这代码怎么???就一句通。,

追答

我是vbnet2010

追问

我要的是vb6.0的

本回答被提问者和网友采纳
相似回答