Results 1 to 10 of 10

Thread: Drive, Dir, and FileListboxes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Drive, Dir, and FileListboxes

    Alright, in the attached image, you can see I have a drive listbox, a dirlist box, and a file listbox... I need the dirlistbox to display the folders in the selected drive in the drive list box and I need the file list box to display the files in the selected folder... How would this be done?
    Attached Images Attached Images  
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Drive, Dir, and FileListboxes

    Code:
    Private Sub Form_Load() 
    Drive1.Drive = "C:" 
    End Sub
    
    Private Sub Drive1_Change() 
    Dir1.Path = Drive1.Drive 
    End Sub
    
    Private Sub Dir1_Change() 
    File1.Path = Dir1.Path 
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: Drive, Dir, and FileListboxes

    works perfectly, except or one thing... if there isnt anything there, and you click the drive, it gives yu and error... also, is there a way I can get a command button to open the selected file in the filelist?
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Drive, Dir, and FileListboxes

    Error trap and that will fix the error.

    What kind of file would you be opening?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: Drive, Dir, and FileListboxes

    it depends, what file they click, like in the image, they could be clicking an exe or a htm
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Drive, Dir, and FileListboxes

    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
    
    Private Const SW_SHOWNORMAL = 1
    
    Private Sub Command1_Click()
        On Error GoTo ErrRun
        With CommonDialog1
            .CancelError = True
            .DialogTitle = "Choose a file to run"
            .ShowOpen
        End With
        ShellExecute Me.hwnd, vbNullString, File1.FileName, vbNullString, "C:\", SW_SHOWNORMAL
    Exit Sub
    ErrRun:
    MsgBox Err & " " & Error
    End Sub

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: Drive, Dir, and FileListboxes

    Umm... I tried that, and it said variable not defined...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Drive, Dir, and FileListboxes

    What variable isn't defined?

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
     
    Posts
    453

    Re: Drive, Dir, and FileListboxes

    umm... CommonDialog1 is hilighted...
    Haikus are easy.
    But sometimes they don't make sense.
    Refrigerator.

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Drive, Dir, and FileListboxes

    That was an example using the CommonDialog. You aren't using it.

    When a piece of code is posted in response to a question it is generally NOT going to work as posted. There will always be something you have to change to fit it into your program, but, the underlying content of the code will generally work.

    You need to modify my example to fit your program.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width