· The drive, directory, and file list boxes are almost always used together to obtain a file name. As such, it is important that their operation be synchronized to insure the displayed information is always consistent.
· When the drive selection is changed (drive box Change event), you should update the directory path. For example, if the drive box is named drvExample and the directory box is dirExample, use the code:
dirExample.Path = drvExample.Drive
· When the directory selection is changed (directory box Change event), you should update the displayed file names. With a file box named filExample, this code is:
filExample.Path = dirExample.Path
· Once all of the selections have been made and you want the file name, you need to form a text string that correctly and completely specifies the file identifier. This string concatenates the drive, directory, and file name information. This should be an easy task, except for one problem. The problem involves the backslash (\) character. If you are at the root directory of your drive, the path name ends with a backslash. If you are not at the root directory, there is no backslash at the end of the path name and you have to add one before tacking on the file name.
· Example code for concatenating the available information into a proper file name and then loading it into an image box is:
Dim YourFile as String
If Right(filExample.Path,1) = "\" Then
YourFile = filExample.Path + filExample.FileName
Else
YourFile = filExample.Path + "\" + filExample.FileName
End If
imgExample.Picture = LoadPicture(YourFile)
Note we only use properties of the file list box. The drive and directory box properties are only used to create changes in the file list box via code.
.
No comments:
Post a Comment