Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create, write and save a text file

Status
Not open for further replies.

Jimreaper

MIS
May 22, 2001
21
US
Hello,
What's the easyies way to :
-create a local txt file
-write to it. ex( file = strSomeText )
-save the file
using vb 6

Thanks
 
This is a procedure that I use to take information on a form and write it to a text file.

First add a commondialog control to your form.

Private Sub Write_ToFile()
'// Writes the registration information to a file.
Dim l_strFileToSave As String

CommonDialog1.fileName = App.Path & LoadResString(155)
CommonDialog1.filter = "Text (*.txt)|*.txt|WordPad (*.wpd)|*.wpd" 'dialog box filter
CommonDialog1.ShowSave
l_strFileToSave = CommonDialog1.fileName
If l_strFileToSave = "" Then Exit Sub
Open l_strFileToSave For Output Access Write As #1
Print #1, vbCrLf & vbCrLf
Print #1, vbTab & vbTab & LoadResString(150) & " " & LoadResString(11) & vbCrLf & vbCrLf & vbCrLf
Print #1, "Registration Form" & vbCrLf
Print #1, "Fax to: " & LoadResString(153) & LoadResString(154) & vbCrLf
Print #1, "Date: " & Date
Print #1, "Product: " & txtProduct.Text
Print #1, "Version: " & App.Major & "." & App.Minor & "." & App.Revision
Print #1, "Serial Number: " & txtSerialNumber.Text & vbCrLf
Print #1, "Company: " & txtCompany.Text
Print #1, "Name: " & txtName.Text
Print #1, "Title: " & txtTitle.Text
Print #1, "Address 1: " & txtAddress1.Text
Print #1, "Address 2: " & txtAddress2.Text
Print #1, "City / Town: " & txtCity.Text
Print #1, "Province / State: " & cboProvSt.Text
Print #1, "Country: " & cboCountry.Text
Print #1, "Postal / Zip Code: " & txtPCZip.Text
Print #1, "Phone Number: " & mebPhone.Text
Print #1, "Fax Number: " & mebFax.Text
Print #1, "E-Mail Address: " & txtEmail.Text & vbCrLf
Print #1, "Comments: " & txtComments.Text
Close #1
End Sub


Thanks and Good Luck!

zemp
 
Use Write # if you are creating a csv file.

;)
 
Zemp,
Thanks! it's perfect, this is all I needed.


Dim sText As String
sText = "test"
Dim l_strFileToSave As String
l_strFileToSave = App.Path & "\attachments\test.txt"
Open l_strFileToSave For Output Access Write As #1
Print #1, sText
Close #1


works like a champ.
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top