标题:【分享】VB6 選擇資料夾or檔案
只看楼主
kedian1968
Rank: 2
等 级:论坛游民
帖 子:15
专家分:15
注 册:2022-2-15
结帖率:33.33%
已结贴  问题点数:5 回复次数:2 
【分享】VB6 選擇資料夾or檔案
問題
CommonDialog能選擇資料夾嗎?
Shl.BrowseForFolder 能秀全資料夾 又 預設資料夾嗎? 查到的預設C:\ 後 D:\不會顯示


程序代码:
Private Sub Command1_Click() '選資料夾
    Dim Shl As Object
    Set Shl = CreateObject("Shell.Application") '創物件
    Set Fd = Shl.BrowseForFolder(0, "選取資料夾", 0, "\") '標題 and 預設路徑\
    If Not Fd Is Nothing Then '非錯誤執行
        Text1.Text = Fd.Items.Item.Path ' 顯示所選取檔案的名稱
    End If
    Set Shl = Nothing '釋放
    Set Fd = Nothing '釋放
End Sub

Private Sub Command2_Click() '選檔案 需物件CommonDialog1
  On Error Resume Next ' 略過錯誤
  CommonDialog1.Flags = cdlOFNHideReadOnly '單選 cdlOFNAllowMultiselect '改為復選
  ' 限制檔案類型
  CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files(*.txt)|*.txt|Batch Files (*.bat)|*.bat"
  CommonDialog1.FilterIndex = 2   ' 預設第2 "|" 項目
  CommonDialog1.ShowOpen ' 顯示「開啟舊檔」對話方塊
  Text1.Text = CommonDialog1.FileName ' 顯示所選取檔案的名稱
End Sub


參考來源
選取資料夾
http://
選擇檔案
http://yes.nctu.edu.tw/vb/2_Ctrl/CommonDialog_ShowOpenSave_Demo.htm
CommonDialog.flags 參數含義
https://blog.
搜索更多相关主题的帖子: 分享 VB6 Nothing Sub Set 
2022-03-10 16:08
cwa9958
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:247
专家分:1228
注 册:2006-6-25
得分:5 
看不明白。
Command1只是显示文件夹(资料夹),
Text1.Text = Fd.Items.Item.Path ' 顯示所選取檔案的名稱
这句也只是显示文件夹,没有显示具体的文件名。
应该没有问题的,
查到的預設C:\ 後 D:\不會顯示,是怎么不能显示?
2022-03-11 08:00
kedian1968
Rank: 2
等 级:论坛游民
帖 子:15
专家分:15
注 册:2022-2-15
得分:0 
Set Fd = Shl.BrowseForFolder(0, "選取資料夾", 0, "C:\")
設成預設C:\ 其他槽看不到

CommonDialog1開啟舊檔 只能選擇檔案
有方式用 CommonDialog1 選資料夾嗎

2022-03-11 10:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-508511-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.678644 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved