Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Lesson XI.

FileListBox, DirectoryListBox, and DriveListBox

Objectives

To use FileListBox, DirectoryListBox, and DriveListBox


To understand how these 3 controls interact in a simple application

Notes
A FileListBox is a list of files in a specified directory. A DirListBox displays the directory structure
of a specified drive. DriveListBoxes lists the drive structure of the users computer.
These three controls are initially independent of each other in the Form. Thus, it is your job to tie
them up together. What you can probably do is to update the contents the FileListBox whenever
the user selects a new folder in the DirListBox. You can also update the directory structure of this
DirListBox whenever the user selects a new drive in the DriveListBox. The primary event of these
controls is Change() when the user selects a new item in these ListBoxes.
The following are the properties of a FileListBox:
Property
Archive

Path

Description
Boolean. Specifies whether or not archive attributes are
displayed. Default is True.
Boolean. Specifies whether or not hidden attributes are
displayed. Default is False.
Integer. Specifies whether or not the user can make
multiple selections
String. Specifies the current path.

Pattern

String. Specifies the files displayed in the FileListBox

ReadOnly

Boolean. Specifies whether or not read-only attributes are


displayed. Default is True.
Boolean. Specifies whether or not system attributes are
displayed. Default is True.

Hidden
MultiSelect

System

The most important method of a DriveListBox is Drive. The drive method returns the current drive
(in the form C: or D:) of the DriveListBox. Using DirectoryListBox, the Path method gives you the
path to the current folder or directory (e.g. C:\myfiles\computer).

Lesson in Action
The application below is a simple file system browser. Using FileListBox, DirectoryListBox, and
DriveListBox, you can view your systems file structure, from its drives to its directories and files.

Private Sub dirDirectory_Change()


filFiles.Path = dirDirectory.Path

End Sub
Private Sub drvDrives_Change()
dirDirectory.Path = drvDrives.Drive
End Sub
Private Sub txtPattern_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
filFiles.Pattern = txtPattern.Text
End If
End Sub
Save your work as Lesson11.vbp.

On your Own
Modify the application you have created in the Lesson in Action section. In a Label, display the
number of files found with the specified pattern in a specified location. When the user selects a
file in the FileListBox, the file name complete with its path (drive and directory) appears in
another Label.

You might also like