如何从按钮单击获取文件路径并将其打印在文本框VB6上

发布于 2025-01-10 08:19:17 字数 306 浏览 0 评论 0原文

我有一个按钮和一个文本框,我想让按钮通过默认路径打开文件夹。

我将举一个例子:

    'C:\Folder\...

    Dim path as string
    path = "C:\Folder\.."
    Dim fso
    set fso = createobject("Scripting FileSystemObjh)

我尝试了一些方法,它只打开文件夹但没有获取文件路径,所以不是我想要做的。

当我选择文件并单击“确定”时,文件路径将打印在文本框中。

先感谢您!

I have a button and a textbox and I want to make the button to open the folder by a default path.

I will give example:

    'C:\Folder\...

    Dim path as string
    path = "C:\Folder\.."
    Dim fso
    set fso = createobject("Scripting FileSystemObjh)

I tried some method where it only opens the folder but doesn't get the file path so not what I want to do.

And when I select the file and click okay the file path to be printed on the textbox.

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雾里花 2025-01-17 08:19:17

如果我了解您的需求,那么以下内容应该为您指明正确的方向。首先,选择以下组件:

微软通用对话框控件6.0 (SP6)

其次,选择以下参考:

微软脚本运行时

第三,将 CommonDialog 控件以及 CommandButton 和 TextBox 拖放到窗体上。输入以下代码:

Option Explicit

Private Sub Command1_Click()
   Dim fso As FileSystemObject
   Dim path As String
   
   path = "c:\temp\"
   
   CommonDialog1.InitDir = path
   CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"
   CommonDialog1.DefaultExt = "txt"
   CommonDialog1.DialogTitle = "Select File"
   CommonDialog1.ShowOpen
   
   Text1.Text = CommonDialog1.FileName
   
   Set fso = New FileSystemObject
   'use fso to do whatever you need
End Sub

If I understand what you need, the following should point you in the right direction. First, select the following Component:

Microsoft Common Dialog Control 6.0 (SP6)

Second, select the following Reference:

Microsoft Scripting Runtime

Third, drop a CommonDialog control onto your form along with the CommandButton and TextBox. Type the following code:

Option Explicit

Private Sub Command1_Click()
   Dim fso As FileSystemObject
   Dim path As String
   
   path = "c:\temp\"
   
   CommonDialog1.InitDir = path
   CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"
   CommonDialog1.DefaultExt = "txt"
   CommonDialog1.DialogTitle = "Select File"
   CommonDialog1.ShowOpen
   
   Text1.Text = CommonDialog1.FileName
   
   Set fso = New FileSystemObject
   'use fso to do whatever you need
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文