Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Adding the File Dialog Boxes

To display a File Open dialog box, your application might contain the following statements:

cdbDialog.DialogTitle = "File Open"
cdbDialog.Filter = "*.txt"   'Show only text files
cdbDialog.FileName = "*.txt" 'Default filename
cdbDialog.ShowOpen           'Trigger the dialog box

All the File Open dialog box buttons and list boxes have property names. Therefore, you can initialize the File Open dialog box to have any default value that best matches your application's needs. When the user selects from and closes the dialog box, your application will have to test the dialog box's FileName and IntDir properties to locate the file the user selected.

To display a File Save dialog box, your application might contain the following statements:

cdbDialog.DialogTitle = "File Save"
cdbDialog.Filter = "*.*"         'Show all files
cdbDialog.FileName = "test.txt"  'Default filename
cdbDialog.ShowSave               ' Trigger the dialog box

Notice that the methods at the end of these last two code fragments have triggered the dialog box's display for the user.

Share ThisShare This

Informit Network