求助 Drive1控件与Dir1 控件关联问题的错误
Private Sub Dir1_Change()
Debug.Print Dir1.Path
End Sub
Private Sub Drive1_Change()
'引用microsoft scripting runtime
Dim fso As New FileSystemObject
If fso.GetDrive(Drive1.Drive).IsReady Then '出错 提示:实时错误‘5’ 无效的过程调用参数
Dir1.Path = Drive1.Drive
Else
MsgBox Drive1.Drive & " 设备没准备好 !"
End If
Set fso = Nothing
End Sub
以上代码是 TOP008 老师帮写的,因前贴已结,所以只好另发一贴了
之初是这样的代码:
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
因点到光驱时,因为没装光盘会出错就改成现在这样,但现在当点其它硬盘时就出错在有注释的那句上。
继续 求助 谢谢!
[解决办法]
Option Explicit
Dim lastDrive As String
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo EH
Dir1.Path = Drive1.Drive
lastDrive = Drive1.Drive
Exit Sub
EH:
If Err.Number = 68 Then
MsgBox "驱动器中没有光盘。", vbExclamation, "抱歉"
Drive1.Drive = lastDrive
Exit Sub
End If
MsgBox "实时错误 " & Err.Number & ":" & vbCrLf & Err.Description
End Sub
Private Sub Form_Load()
lastDrive = Drive1.Drive
End Sub