Browse » Home
Sunday, December 22, 2013
How to Use a Text Box for File Name VB6
1. Create a new dialog box object. Any object you use in the VB language first needs a definition and assignment to a variable. The following code creates your VB object:Dim dialog As CommonDialog
2. Set the dialog window properties. The first property sets the text seen at the top of the dialog window. The second filters the types of file extensions allowed. For instance, if your application only allows users to save as a text file, the filter only allows '*.txt' in the 'Save as type' drop down box. The following code sets your VB 'Save' properties:dialog.DialogTitle = 'Save Your File'
dialog.Filter = 'Text File (*.txt)'
3. Show the dialog box to the user. The dialog box is set up, but it is not visible to the user until you manually display it. The following code displays the window to the user:dialog.ShowSaveThe dialog box opens using this code, and when the user clicks 'Save,' the file is saved to the hard drive.
4. Show a message box if there was an error or the user cancels the save. The following code displays an alert if the save function fails:If Err Then
Msgbox 'There was an error saving your file'
End If