vb6 - vb6中未就绪驱动器的解决方案

标签 vb6 error-handling drive

我需要一个更好的解决方案来处理未就绪的驱动器,并且希望能够查看和更改我的rw驱动器中的文件。不幸的是,它总是会导致驱动器未就绪错误,而我唯一能做的就是处理错误。

到目前为止,我已经做到了:

我的云端硬盘:

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

最佳答案

您是否考虑过使用Microsoft脚本运行时(scrrun.dll)的FileSystemObject?

Public Function CheckDrivePathReady(IN_sPath as String) As Boolean
    Dim myFSO As Scripting.FileSystemObject
    Dim myDrive As Scripting.Drive
    Dim myDriveName As String

    'Create a new FileSystemObject
    Set myFSO = New Scripting.FileSystemObject

    'Get drive name from path.
    myDriveName = gFSO.GetDriveName(IN_sPath)
    'Create a "Drive" object to test the properties of.
    Set myDrive = gFSO.GetDrive(myDriveName)

    'Test if the drive is usable.
    '(there are more properties than just "ready" that can be tested)
    If myDrive.IsReady Then
        'Work with ready drive here....

    End If

    'Make sure to clean up when done.
    set myDrive = Nothing
    Set myFSO = Nothing
End Function

您将需要在项目引用中包括Microsoft Scripting Runtime,但是我发现FileSystemObject在使用驱动器和路径时非常重要。

关于vb6 - vb6中未就绪驱动器的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9172747/

相关文章:

forms - VISUAL BASIC 6::使用计时器卸载 Splash 表单

class - VB6 类有析构函数吗?

vb.net - 在 Visual Basic 2010 中动态循环图片框控件似乎不遵循任何顺序

node.js - 表达错误处理或域?

error-handling - Firestore每秒1写入限制错误(关闭)

json - 用于托管 JSON 的 Google Drive 'host' 终止(2016 年 8 月)

python - 使用 Python 映射 Windows 驱动器的最佳方法是什么?

ms-access - 在 Recordset 循环中迭代 ADODB 字段

python - 在Python中处理类中的错误

javascript - 来自未发布的 Google Drive 电子表格的 JSON 数据?