You are here: DEVPPL Forum Programming Visual Basic Forum
NOTIFICATIONS
54.062
MEMBERS
15.677
TOPICS
62.242
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

Text File

0

Loading

Text File

Postby Darren » Tue May 03, 2011 1:36 pm

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()
Darren
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 1:30 pm
Highscores: 0
Arcade winning challenges: 0

Text File - Sponsored results

Sponsored results

Login to get rid of ads

 

0

Loading

Re: Text File

Postby Jblues » Tue May 03, 2011 2:59 pm

try this

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

Loading

Re: Text File

Postby Darren » Tue May 03, 2011 3:08 pm

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 .
Darren
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 1:30 pm
Highscores: 0
Arcade winning challenges: 0
0

Loading

Re: Text File

Postby Jblues » Tue May 03, 2011 3:14 pm

Something like this:

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

Loading

Re: Text File

Postby Darren » Tue May 03, 2011 3:32 pm

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
Darren
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 1:30 pm
Highscores: 0
Arcade winning challenges: 0
0

Loading

Re: Text File

Postby Jblues » Tue May 03, 2011 3:55 pm

declare the streamwriter

Dim objStreamWriter As System.IO.StreamWriter
Jblues
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 12:08 pm
Highscores: 0
Arcade winning challenges: 0
0

Loading

Re: Text File

Postby Darren » Tue May 03, 2011 5:04 pm

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
Darren
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 1:30 pm
Highscores: 0
Arcade winning challenges: 0
0

Loading

Re: Text File

Postby Jblues » Tue May 03, 2011 5:31 pm

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()
Jblues
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 12:08 pm
Highscores: 0
Arcade winning challenges: 0
0

Loading

Re: Text File

Postby Darren » Tue May 03, 2011 6:01 pm

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
Darren
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 1:30 pm
Highscores: 0
Arcade winning challenges: 0
0

Loading

Re: Text File

Postby Darren » Tue May 03, 2011 6:05 pm

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
Darren
 
Reputation: 0
Posts: 13
Joined: Tue May 03, 2011 1:30 pm
Highscores: 0
Arcade winning challenges: 0
Next
^ Back to Top