Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / August 2006



Tip: Looking for answers? Try searching our database.

Append new line to Text File

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 31 Aug 2006 03:22 GMT
I would like to append a new line to a text file for example:

somethin somethinsomethin2 some
New Line

How would I go about doing this?

Thanks
Dan
Henning - 31 Aug 2006 03:36 GMT
> I would like to append a new line to a text file for example:
>
[quoted text clipped - 5 lines]
> Thanks
> Dan

Open MyFile For Append as #filnum
Print or Write to end of file.

/Henning
Rick Rothstein (MVP - VB) - 31 Aug 2006 03:45 GMT
>I would like to append a new line to a text file for example:
>
> somethin somethinsomethin2 some
> New Line
>
> How would I go about doing this?

Dim FF As Long
Dim FileNameAndPath As String
Dim NewLineToOutput As String
FileNameAndPath = {fill in with your filename and its path}
NewLineToOutput = "New Line"
FF = FreeFile
Open FileNameAndPath For Output As #FF
Print #FF, NewLineToOutput
Close #FF

Rick
Randy Birch - 31 Aug 2006 03:53 GMT
Ha! -- For Append, not For Output.  <g>

Signature

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.

>I would like to append a new line to a text file for example:
>
> somethin somethinsomethin2 some
> New Line
>
> How would I go about doing this?

Dim FF As Long
Dim FileNameAndPath As String
Dim NewLineToOutput As String
FileNameAndPath = {fill in with your filename and its path}
NewLineToOutput = "New Line"
FF = FreeFile
Open FileNameAndPath For Output As #FF
Print #FF, NewLineToOutput
Close #FF

Rick
Rick Rothstein (MVP - VB) - 31 Aug 2006 04:11 GMT
> Ha! -- For Append, not For Output.  <g>

Damn! Thanks for catching that...

Dim FF As Long
Dim FileNameAndPath As String
Dim NewLineToOutput As String
FileNameAndPath = {fill in with your filename and its path}
NewLineToOutput = "New Line"
FF = FreeFile
Open FileNameAndPath For Append As #FF
Print #FF, NewLineToOutput
Close #FF

Rick
Dan - 31 Aug 2006 14:29 GMT
Open App.Path & "\sinfo.txt" For Append As #1
Print #1, title & " " & Artist
Close #1

When I use the above code in a file that already has one line of text,
it just puts the stuff at the end of the line not on a new line. (I
don't want to use write because I don't want quotes around my text).
Rick Rothstein (MVP - VB) - 31 Aug 2006 14:56 GMT
> Open App.Path & "\sinfo.txt" For Append As #1
> Print #1, title & " " & Artist
[quoted text clipped - 3 lines]
> it just puts the stuff at the end of the line not on a new line. (I
> don't want to use write because I don't want quotes around my text).

That means the existing line you have in your file was not put there with
the above code. The Print statement (as written) puts the new line of text
into the file with a trailing Windows newline character sequence (carriage
return followed by a line feed), so each line it adds to the file goes on
the next line. If you open your existing file in a text editor, put the text
cursor at the end of the file (it will be right after the last letter of the
last word), hit the Enter Key (to put a newline character sequence after it)
and then save the file back out... then the above code will work correctly
from there on out. The key to maintaining a file of data is consistency in
how data is added to the file.

Rick
Henning - 31 Aug 2006 15:07 GMT
> Open App.Path & "\sinfo.txt" For Append As #1
> Print #1, title & " " & Artist
[quoted text clipped - 3 lines]
> it just puts the stuff at the end of the line not on a new line. (I
> don't want to use write because I don't want quotes around my text).

Print #1, vbcrlf  & title & " " & Artist

/Henning
Henning - 31 Aug 2006 15:10 GMT
> Open App.Path & "\sinfo.txt" For Append As #1
> Print #1, title & " " & Artist
[quoted text clipped - 3 lines]
> it just puts the stuff at the end of the line not on a new line. (I
> don't want to use write because I don't want quotes around my text).

To keep the end of line as before,
Print #1, vbcrlf  & title & " " & Artist;

/Henning
Dan - 31 Aug 2006 16:49 GMT
thanks - it works now!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.