Mener du at programmet selv skal finde ud af, hvilket drevbogstav CD-rom drevet er tildelt, eller skal man blot kunne vælge det rette? Det sidste er nemt, der er en kontrol til det samme.
Med denne funktion kan du se hvad de forskellige drev er sat til.
Option Explicit Private Declare Function GetDriveTypeA Lib "Kernel32" (ByVal nDrive As String) As Long
Function HentDriveType( pcDrev ) Select Case GetDriveTypeA(UCase(Left( pcDrev, 1) & ":\"))
Case 0 HentDriveType := "Kan ikke afgøre typen" Case 1 HentDriveType := "Drevet eksisterer ikke" Case 2 HentDriveType := "Floppy disk" Case 3 HentDriveType := "Hard disk" Case 4 HentDriveType := "Net drev" Case 5 HentDriveType := "CD-Rom" Case 6 HentDriveType := "RAM Disk" End Select End Function
The following code loops through all your computer's drive letters, to see which letter is mapped to the CD-ROM drive. It returns the drive letter if successful or an empty string on failure.
Public Function BI_GetCDROMDrive() As String Dim lType As Long Dim i As Integer Dim tmpDrive As String Dim found As Boolean
On Error GoTo ErrorHandler
'Loop thru A-Z. If found, exit early. For i = 0 To 25
tmpDrive = Chr(65 + i) & ":\" lType = GetDriveType(tmpDrive) 'Win32 API function If (lType = DRIVE_CDROM) Then 'Win32 API constant found = True Exit For End If Next If Not found Then tmpDrive = "" End If
Private Sub Command1_Click() Dim CDROM as String CDROM = Left(App.Path, 1) End Sub
-- CDROM indeholder nu bogstavet for cdrom drevet...
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.