1 Attachment(s)
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?
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
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?
Re: Drive, Dir, and FileListboxes
Error trap and that will fix the error.
What kind of file would you be opening?
Re: Drive, Dir, and FileListboxes
it depends, what file they click, like in the image, they could be clicking an exe or a htm
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
Re: Drive, Dir, and FileListboxes
Umm... I tried that, and it said variable not defined...
Re: Drive, Dir, and FileListboxes
What variable isn't defined?
Re: Drive, Dir, and FileListboxes
umm... CommonDialog1 is hilighted...
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.