-
Why do I get an error when I try this?
Code:
Private Sub Drive1_Change()
Dim sDrive$
Dir1.Path = Drive1.Drive ' error occurs here.
sDrive = Drive1.Drive
Label6.Caption = fn_EvalDriveType(sDrive)
End Sub
Function fn_EvalDriveType(sDrive As String) As String
Dim lD_Type as Variant,
lD_Type = GetDriveType(sDrive & Chr(0))
End Function
The error occurs when you select a network drive eg 'g: [\\MA000013\F]'.
Also, why does the MSDN in VS6 say that the GetDriveType call returns a string eg 'DRIVE_UNKNOWN'when the declare is a long? :Confused:
-
What error are you actually getting?
-
GetDriveType returns a long, you can declare constants with these values (like DRIVE_UNKNOWN), not sure if they're in the api textviewer (can't check right now...)
-
Mark, the error was something systemy - I solved it by forcing it to carry on on errors.
Crazy,
How? I've put the constants in, but how do I force it to link the long 5 to the constant DRIVE_CDROM? I want to put it into a string.
such as
label6.caption= <Drive_Type> has x freespace from a total of y. :confused:
Here's what I do at the moment . . .
Code:
Function fn_EvalDriveType(sDrive As String) As String
On Error Resume Next
Dim lD_Type As Long, lFree As Currency, ltotal As Long, sType$, sID$, lClusSize As Long, lByteSize As Long, lFreeClus As Long, lTotClus As Long
lD_Type = GetDriveType(sDrive & "\" & Chr(0))
Select Case lD_Type
Case 1
sType = "Drive_Unknown"
Case 2
sType = "Drive_Removable"
Case 3
sType = "Drive_Fixed"
Case 4
sType = "Drive_Remote"
Case 5
sType = "Drive_CDROM"
Case 6
sType = "Drive_RAMDisk"
Case Else
sType = "Error - Invalid Drive/Dir"
End Select
GetDiskFreeSpace Left(sDrive, 2) & "\" & Chr(0), lClusSize, lByteSize, lFreeClus, lTotClus
lFree = ((lByteSize * lClusSize) / 1024) * ((lFreeClus) / 1024)
ltotal = ((lByteSize * lClusSize) / 1024) * ((lTotClus) / 1024)
sID = "Mb"
Select Case ltotal
Case Is > 1024
ltotal = ltotal / 1024
lFree = lFree / 1024
sID = "Gb"
End Select
barDisk.Max = ltotal
barDisk.Value = lFree
fn_EvalDriveType = sType & vbCrLf & (lFree) & sID & " of " & (ltotal) & sID
End Function
Bearing in mind that this only me playing with API and not serious code!!! :D