使用VB 6
我的代码。
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 Drive
现在它正在显示我的Project文件夹,它应显示c Drive
如何为这种情况编写代码?
需要VB6代码帮助。
答案 0 :(得分:1)
这将解决您的要求:
要获取FileSystemObject
,您必须在项目中将引用添加到“Microsoft Scripting Runtime”。
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 =“”
答案 1 :(得分:-1)
您要找的答案在VBCity site 那里的代码示例允许您完全按照您的要求进行操作。