The use of VB file System control

Source: Internet
Author: User
Tags file system valid root directory

Using File system controls (Directory list box, Drive list box, and file ListBox)

Many applications must display information about disk drives, directories, and files. To enable users to take advantage of file systems, Visual Basic provides two options. You can use the standard dialog boxes provided by the CommonDialog control, or create a custom dialog using a combination of the three special controls such as DirListBox, DriveListBox, and FileListBox.
File system controls enable users to check for and select from available disk files in their applications. If you want only the standard open File or Save dialog box, consider using the CommonDialog control.
For more information, see "Using the CommonDialog control" earlier in this chapter.

Sample application: Winseek.vbp
Many code samples come from the Winseek sample application (WINSEEK.VBP), which is listed in the Samples directory.

Check File system
Each file system control is carefully designed to combine flexible, complex file system checks with simple programming methods. Each control automatically performs a file data acquisition task, but you can also write code to customize the appearance of the control and specify the information that is displayed.

File system controls can be used separately or in combination. When used in combination, you can write code in the event procedures of each control to determine how they interact with each other. You can also let them operate independently. Figure 7.17 shows the three controls that are used together.
File system controls get everything from the operating system automatically; You can access this information or determine the information that each control displays through its properties. For example, the contents of the current working directory are displayed by default (that is, the directory that launches the application, or the current directory that is changed by the ChDir statement).
The application can also display a list of files whose names match a pattern, such as *.frm. Simply draw a list of files on the form and set its Pattern property to *.frm. At run time, the pattern attribute can be specified with the following code:
File1.pattern = "*. FRM "

File system controls make the operation very flexible, which is not possible with the CommonDialog control. You can mix, match, and control how they look and interact in a variety of ways.
If the goal is to enable users to open and save files, the CommonDialog control provides a ready-made set of dialog boxes for these operations. These dialog boxes are also used by many other microsoftwindows based applications and therefore have a standardized look. These controls also recognize the available network drives.
For more information, see "Using the CommonDialog control" earlier in this chapter.

Drive list Box
The Drive list box is a drop-down list box. Displays the current drive on the user's system by default. When the control receives the focus, the user can enter any valid drive identifier or click the arrow to the right of the Drive list box. When the user clicks the arrow, it pulls the list box down to enumerate all the valid drives. If the user selects a new drive from, the drive appears at the top of the list box. You can use code to check the Drive property to determine which drive is currently selected. The application can also specify the drive that appears at the top of the list box by using the following simple assignment statement:
drive1.drive = "C:\"
The Drive list box displays available valid drives. Selecting a drive from a list box does not automatically change the current working drive, but the Drive property changes the drive at the operating system level, which is simply a parameter to the ChDrive statement:
ChDrive drive1.drive

Directory list box
The Directory list box displays the current drive directory structure on the user's system, starting at the highest level of the directory. Initially, the current directory name is highlighted, and the current directory is indented to the root directory along with the directory in the directory hierarchy that is higher than its level. Subdirectories in the current directory in the Directory list box are also indented to display. Each table of contents item is highlighted in turn when you move up or down in the list.

Identify a single directory
Each directory in the list box Associates an integer identifier that can be used to identify a single directory. The CommonDialog control does not provide this functionality. The directory specified by the Path attribute (Dir1.path) always has a ListIndex value of 1. The directory immediately above it has a ListIndex value of 2, then the previous is ListIndex-3, and so on. The first subdirectory of the Dir1.path has a ListIndex value of 0. As shown in Figure 7.18, if the first level subdirectory has more than one directory, the ListIndex value of each directory is 1, 2, 3 ... are sorted sequentially.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.