Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have been working on a program that is taking a series of textbox fields (as entered by the user) and trying to have them output to a formatted text file.
I have been able to get the data output just fine, but it is far from readable format when I open the text file. Is there any way to do this?
I would like to at least be able to insert line breaks after each textbox is written to the file so it can be easily viewed.
Thanks

I snippet of code to show exactly how you are writing the file would help then people would be able to tell you where you are going wrong.
Stuart

Try this,
Private Sub Stuff
Open ("A:\a.txt") For Output As #1
Print #1, "HHH"
print #1, Text1.text
Close #1
MsgBox "Done"End Sub

Here is the code I am trying to use. It works, but it does not format the output to the file. I would actually like to have each lable / text pair on one line by itself.
If fsys.FileExists(filename) Then
MsgBox "File exists... Appending new data to file"Open filename For Append As #1
Print #1, Label1, Text1, Label2, Text2, Label3, Text3, Label4, Text4, Label; 5, Text5, Label6, Text6, Label7, Text7
Close #1
Else
MsgBox "Incident recorded" fsys.CreateTextFile filename
Open filename For Output As #1
Print #1, Label1, Text1, Label2, Text2, Label3, Text3, Label4, Text4, Label; 5, Text5, Label6, Text6, Label7, Text7
Close #1
End If

you can either have
Print #1, Labe11
print #1, Text1
etcOr have
print #1, Lebel1 & vbcrlf, Text1 & vbcrlf
CRLF = Carriage Return Line Feed
which basically equates to a new line when you press enter either way would work

ok just tried it and there is one slight problem with the above, heres the correct way of using the VBCRLF code
Private Sub Stuff()
Open ("A:\a.txt") For Output As #1
Print #1, TextBox1.Text & vbCrLf & TextBox2.Text & Label2.Caption
Close #1
MsgBox "Done"Text1.text = Hello
Text2.text= World
Label3.caption = Againso when you open a.txt
you will have
Hello
World
Againfor the text and label pairs you have to do this
Open ("A:\a.txt") For Output As #1
Print #1, TextBox1.Text & " " & Label1.caption & vbCrLf & TextBox3.Text & " " & Label2.caption
Close #1
MsgBox "Done"

If you are using so many controls why not use a control array. It makes the code so much easier.
dim a as Integer
Open filename For Append As #1
for a = 0 to 7
Print #1, Label1(a),
Print #1, Text1(a) & vbCrLf,
next
Close #1
Stuart

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |