How to save a file in VB 6

5 pts.
Tags:
CommonDialog
VB 6
Visual Basic 6
How to save any type of file to a particular folder after we get the file from common dialog control in VB 6.0

Answer Wiki

Thanks. We'll let you know when a new response is added.

The common dialog control does not open or save the files, it just show a dialog in which the user can select the files.
If you want to modify and save the file selected by the user, after the call to the common dialog you need to open the file, for append/output, write what you need, and then close the file.

Here is an example:

<pre>Private Sub Command2_Click()
' Set filters.
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter.
CommonDialog1.FilterIndex = 2
' Display the Open dialog box.
CommonDialog1.ShowOpen
' get a free file number
file1 = FreeFile
'open the file
Open CommonDialog1.FileName For Append As file1
' Add some text to the file
Print #file1, "This is the new line"
Close #file1
End Sub</pre>

The file name contains the full path.

You could also open 2 files, one for input, and other (in some different location) for output, and write in the second file what you read from the first one.

Hope this helps.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following