2012-02-07 3 views
2

아직 제공되지 않은 드라이브를 처리하고 rw 드라이브에서 파일을보고 변경할 수 있기를 원한다면 더 나은 솔루션이 필요합니다. 불행히도 그것은 항상 드라이브 unready 오류를 제공하고 내가 할 수있는 유일한 것은 오류를 처리하는 것입니다.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 
+0

@Deanna ty "영어로 다시 작성하고 형식이 지정된 코드를 약간 개선했습니다." lol 사실은 통해 UR보다 vb6에 나는 희망이 이것에 대한 답변을 찾을 수 있습니다. 아직 웹 검색 중이지만 적절한 답변을 찾을 수 없습니다. –

+0

죄송합니다. 변경 메시지를 기꺼이 받아 보았습니다. 시스템에서 드라이브를 사용할 수 없다고보고 한 경우 오류 처리가 자체 옵션 일 수 있습니다. – Deanna

답변

1

Microsoft Scripting Runtime (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 스크립팅 런타임을 포함해야합니다,하지만 난 드라이브와 경로로 작업 할 때 값을 헤아릴 수 FileSystemObject를 발견했다.

+0

그래, 실수로 인한 것보다 .. 나는 이것으로 많은 운전 상황을 정의 할 수있다. 감사. –

0

imperialdir은 무엇입니까? 예 : 파일 목록 상자입니까? Path 속성은 "k : \"와 같이 존재하는 경로가있는 경우에도 항상 설정하려고하면 오류가 발생합니다. 일부 개체에는 읽기 전용 Path 속성이 있습니다. CheckDrive 함수의 이름이 RootPathOnDrive입니다.

+0

DirListBox라는 vb6 구성 요소와 다른 모든 사람들이 vb6을 사용하여 프로젝트에서 일부 폴더 작업을 할 때 DriveListBox와 함께 사용합니다. –

+0

해당 함수의 이름을 지정하는 데 감사드립니다. –

관련 문제