?
Solved

DriveListBox Question

Posted on 2006-06-01
4
Medium Priority
?
384 Views
Last Modified: 2008-02-01
Hi Guys.

As you all probably know, there are 3 common types of drive shown by the DriveListBox control in VB6.

I want to set one so it only shows physical hard drives (not CD/Floppy or Network Drives).

Any Ideas?
0
Comment
Question by:NAORC
  • 4
4 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16806208
Hi,

Whilst populating the entries in the Combo-Box, you'll need to query the physical attributes of each drive on the system, and only add to the DriveListBox if applicable, for example:

  Dim objDrive As Object

  For Each objDrive In CreateObject("Scripting.FileSystemObject").Drives

        Select Case objDrive.DriveType
            Case 0 ' Unknown
            Case 1 ' Removable Drive
            Case 2
                  (Add objDrive.DriveLetter to your DriveListBox here)
            Case 3 ' Network Drive
            Case 4 ' CD-ROM Drive
            Case 5 ' RAM Disk Drive
            Case Else
        End Select

  Next objDrive


'

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16806262
Alternatively, with a known drive letter, say "A", "B", "C", "Z", etc, the following code may help...

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Function strDriveType(ByVal strDrive As String) As String

   strDrive = Left$(Trim$(strDrive), 1) & ":\"

   Select Case (GetDriveType(strDrive))

      Case 0: strDriveType = "Unknown"
      Case 1: strDriveType = "Non-existent"
      Case 2: strDriveType = "Removable drive"
      Case 3: strDriveType = "Fixed drive"
      Case 4: strDriveType = "Network drive"
      Case 5: strDriveType = "CD-ROM drive"
      Case 6: strDriveType = "RAM disk"
      Case Else: strDriveType = "Unknown drive type"

  End Select

End Function



Usage:
MsgBox strDriveType("C")
or
MsgBox strDriveType("A")


BFN,

fp.

0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 1500 total points
ID: 16806282
Taking this a stage further...

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Function blnValid_Drive(ByVal strDrive As String) As Boolean

   strDrive = Left$(Trim$(strDrive), 1) & ":\"

   Select Case (GetDriveType(strDrive))

      Case (2), (3)
            blnValid_Drive = True

      Case Else
            blnValid_Drive = False

  End Select

End Function


Usage:
If blnValid_Drive("C") Then
   <Add Drive C to DriveListBox>
End If

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16920171
Thanks for accepting my answer.

If you needed further assistance you need not have graded as a 'B'; you could have just written another comment.

BFN,

fp.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question