| You are here: DEVPPL ‹ Forum ‹ Programming ‹ Visual Basic Forum |
NOTIFICATIONS
|
|
|||||||||||||||
Login |
Text File
16 posts
• Page 1 of 2 • 1, 2
0
Text File
Hi ,
I have a form that has a rich text boxes that write to a txt file It works but the two lines in the text file are in one long line How can a make the code write to seperate lines
Code
Dim sfd As New SaveFileDialog
sfd.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
sfd.ShowDialog()
Dim writer As New System.IO.StreamWriter(sfd.FileName)
writer.Write(RichTextBox1.Text)
writer.Write(RichTextBox2.Text)
writer.Close()
I have a form that has a rich text boxes that write to a txt file It works but the two lines in the text file are in one long line How can a make the code write to seperate lines
Code
Dim sfd As New SaveFileDialog
sfd.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
sfd.ShowDialog()
Dim writer As New System.IO.StreamWriter(sfd.FileName)
writer.Write(RichTextBox1.Text)
writer.Write(RichTextBox2.Text)
writer.Close()
- Darren
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 1:30 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
try this
writer.Write(RichTextBox1.Text)
writer.Write(vbNewline)
writer.Write(RichTextBox2.Text)
writer.Write(RichTextBox1.Text)
writer.Write(vbNewline)
writer.Write(RichTextBox2.Text)
- Jblues
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 12:08 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
jblues
Fantastic It works beautiful Many thanks appreciate your time in helping me .
If I may ask another question how can I extend the code so page 2 contents get added to the same text file without over writing it .
Fantastic It works beautiful Many thanks appreciate your time in helping me .
If I may ask another question how can I extend the code so page 2 contents get added to the same text file without over writing it .
- Darren
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 1:30 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
Something like this:
objStreamWriter = System.IO.File.AppendText _
("file")
objStreamWriter.WriteLine _
(RichTextBox1.Text & vbNewline & RichTextBox2.Text)
objStreamWriter.Close()
objStreamWriter = System.IO.File.AppendText _
("file")
objStreamWriter.WriteLine _
(RichTextBox1.Text & vbNewline & RichTextBox2.Text)
objStreamWriter.Close()
- Jblues
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 12:08 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
jblues ,
Thanks once again for your help Does this code get added to existing one above or is it completely on it's own I tried it on it's own and the debug through this error message up
Error 1 'StreamWriter' is a type in 'IO' and cannot be used as an expression.
Error 2 'objStreamWriter' is not declared. It may be inaccessible due to its protection level.
Error 3 'objStreamWriter' is not declared. It may be inaccessible due to its protection level. Thanks
Thanks once again for your help Does this code get added to existing one above or is it completely on it's own I tried it on it's own and the debug through this error message up
Error 1 'StreamWriter' is a type in 'IO' and cannot be used as an expression.
Error 2 'objStreamWriter' is not declared. It may be inaccessible due to its protection level.
Error 3 'objStreamWriter' is not declared. It may be inaccessible due to its protection level. Thanks
- Darren
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 1:30 pm
- Highscores: 0
- Arcade winning challenges: 0
- Jblues
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 12:08 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
jblues,
It is very kind of you to take the time to reply,but may I ask is this a seperate code or added to the one above Thank you appreciate your time Regards
It is very kind of you to take the time to reply,but may I ask is this a seperate code or added to the one above Thank you appreciate your time Regards
- Darren
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 1:30 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
use the declaration code before the other code so
Dim sfds As New SaveFileDialog
sfds.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
sfds.ShowDialog()
Dim objStreamWriter As System.IO.StreamWriter(sfds.FileName)
objStreamWriter = System.IO.File.AppendText _
("file") ' this is where you put the name of the file.
objStreamWriter.WriteLine _
(RichTextBox1.Text & vbNewline & RichTextBox2.Text)
objStreamWriter.Close()
Dim sfds As New SaveFileDialog
sfds.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
sfds.ShowDialog()
Dim objStreamWriter As System.IO.StreamWriter(sfds.FileName)
objStreamWriter = System.IO.File.AppendText _
("file") ' this is where you put the name of the file.
objStreamWriter.WriteLine _
(RichTextBox1.Text & vbNewline & RichTextBox2.Text)
objStreamWriter.Close()
- Jblues
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 12:08 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
jblues,
I have applied the code as you suggested this is the error message Plus no text file was created
Error 2 'objStreamWriter' is not declared. It may be inaccessible due to its protection level.
Plus it had a squiddly line under (sfd.FileName) Array bounds cannot appear
I'm sorry I am hard work but this is a steep learning curve for me sorry to be a pain Regards
I have applied the code as you suggested this is the error message Plus no text file was created
Error 2 'objStreamWriter' is not declared. It may be inaccessible due to its protection level.
Plus it had a squiddly line under (sfd.FileName) Array bounds cannot appear
I'm sorry I am hard work but this is a steep learning curve for me sorry to be a pain Regards
- Darren
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 1:30 pm
- Highscores: 0
- Arcade winning challenges: 0
0
Re: Text File
jblues,
So you can understand what I am trying to make is a two page form
First Page First Name
Surname
Age
Gender
Second Page
First Record you bought
Last record you bought
All sent to a text file
Regards
So you can understand what I am trying to make is a two page form
First Page First Name
Surname
Age
Gender
Second Page
First Record you bought
Last record you bought
All sent to a text file
Regards
- Darren
- Reputation: 0
- Posts: 13
- Joined: Tue May 03, 2011 1:30 pm
- Highscores: 0
- Arcade winning challenges: 0
|
|