Vb6 当打开的对话框找不到以前选择的路径时,如何显示特定的驱动器?

Vb6 当打开的对话框找不到以前选择的路径时,如何显示特定的驱动器?,vb6,Vb6,使用vb6 我的密码 CommonDialog1.DialogTitle = "Open File" CommonDialog1.Filter = "Database (1.mdb) |1.mdb" CommonDialog1.FilterIndex = 1 CommonDialog1.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly CommonDialog1.CancelError = True On Error Resume Next Com

使用vb6

我的密码

CommonDialog1.DialogTitle = "Open File"
CommonDialog1.Filter = "Database (1.mdb) |1.mdb"
CommonDialog1.FilterIndex = 1
CommonDialog1.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
CommonDialog1.CancelError = True
On Error Resume Next
CommonDialog1.ShowOpen
If Err Then
    MsgBox "Select Database"
    Exit Sub
End If
我正在项目中使用“打开”对话框。当我运行项目时,我从远程系统中选择了该文件

假设远程系统不可用,下次我选择打开对话框时,打开对话框应该显示c驱动器

现在它正在显示我的项目文件夹,它应该显示c驱动器

如何为这种情况编写代码


需要VB6代码帮助。

您要寻找的答案在
这里的代码示例允许您完全按照自己的要求进行操作

您要寻找的答案在
这里的代码示例允许您完全按照自己的要求进行操作

这将解决您的问题:

要获取FileSystemObject,必须在项目中添加对“Microsoft脚本运行时”的引用

Dim fs As New FileSystemObject
Dim currentDir As String
currentDir = fs.GetParentFolderName(CommonDialog1.FileName)
If fs.FolderExists(currentDir) Then
    CommonDialog1.InitDir = currentDir
Else
    CommonDialog1.FileName = ""
    CommonDialog1.InitDir = "C:\"
End If
编辑:
您还必须设置CommonDialog1.FileName=

这将解决您的问题:

要获取FileSystemObject,必须在项目中添加对“Microsoft脚本运行时”的引用

Dim fs As New FileSystemObject
Dim currentDir As String
currentDir = fs.GetParentFolderName(CommonDialog1.FileName)
If fs.FolderExists(currentDir) Then
    CommonDialog1.InitDir = currentDir
Else
    CommonDialog1.FileName = ""
    CommonDialog1.InitDir = "C:\"
End If
编辑: 您还必须设置CommonDialog1.FileName=