vb6中未就绪驱动器的解决方案
我需要一个更好的解决方案来处理未就绪的驱动器,并且希望能够查看和更改我的读写驱动器中的文件。不幸的是,它总是给出驱动器未就绪错误,我唯一能做的就是处理该错误。
到目前为止,我已经这样做了:
我的驱动器:
Private Sub imperialdrive_Change()
On Error GoTo I_have_a_baad_feeling_about_this
imperialdir.Path = RootPathOnDrive(imperialdrive.Drive)
Exit Sub
I_have_a_baad_feeling_about_this:
If Err.Number = 68 Then
MsgBox "The selected drive is not available at the moment.", vbOKOnly, "I feel a disturbance in the force."
Else
MsgBox Err.Number & " " & Err.Description, vbCritical, "There is a Bounty Hunter here."
End If
End Sub
我的功能:
'Such a bad choise for a function name
'It sounds like doing smt more than changing the name of drive lol
Public Function RootPathOnDrive(ByVal Drive)
'So how it comes as "k:" instead of "k:\" Is it really cause its not ready? Both ways i should try reaching "k:\"
RootPathOnDrive = Left(Drive, 1) & ":\"
End Function
I need a better solution for handling unready drives and want to be able to see and change files in my rw-drive. Unfortunately it always gives drive unready error and the only thing that I can do is handle the error.
So far I've done this:
My Drive:
Private Sub imperialdrive_Change()
On Error GoTo I_have_a_baad_feeling_about_this
imperialdir.Path = RootPathOnDrive(imperialdrive.Drive)
Exit Sub
I_have_a_baad_feeling_about_this:
If Err.Number = 68 Then
MsgBox "The selected drive is not available at the moment.", vbOKOnly, "I feel a disturbance in the force."
Else
MsgBox Err.Number & " " & Err.Description, vbCritical, "There is a Bounty Hunter here."
End If
End Sub
My Function:
'Such a bad choise for a function name
'It sounds like doing smt more than changing the name of drive lol
Public Function RootPathOnDrive(ByVal Drive)
'So how it comes as "k:" instead of "k:\" Is it really cause its not ready? Both ways i should try reaching "k:\"
RootPathOnDrive = Left(Drive, 1) & ":\"
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否考虑过使用属于 Microsoft 脚本运行时 (scrrun.dll) 一部分的 FileSystemObject?
您需要在项目引用中包含 Microsoft Scripting Runtime,但我发现 FileSystemObject 在使用驱动器和路径时非常有用。
Have you looked into using the FileSystemObject that is part of the Microsoft Scripting Runtime (scrrun.dll)?
You will need to include the Microsoft Scripting Runtime in your project references, but I have found the FileSystemObject to be invaluable when working with drives and paths.
Imperialdir是什么?例如,它是一个文件列表框吗?
当您尝试设置 Path 属性时,即使您知道存在路径(例如 "k:\" ), Path 属性是否总是抛出错误?某些对象具有只读的 Path 属性。
函数 CheckDrive 的更好名称是 RootPathOnDrive。
What is imperialdir? E.g., is it a filelistbox?
Is the problem that the Path property always throws an error when you try to set it, even with a path you know exists, like "k:\" ? Some objects have a Path property that is read-only.
Better name for function CheckDrive would be RootPathOnDrive.