Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Adding onto a text file, Instead of saving over.


Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2003, 11:00 PM
tHe LiNk tHe LiNk is offline
Newcomer
 
Join Date: Apr 2003
Posts: 15
Question Adding onto a text file, Instead of saving over.


Hi, i've been browsing the forums for several weeks now, thought i'd take a post with a problem that has been annoying me.

I'm trying to save onto a text file (i know how to normally do it). But instead, i want to add onto the end of the text file, not save over what is already there. My visual basic knowledge is pretty average, so don't wonder off on me

EDIT: Just to clarify what i meant, heres an explanation of the type of code i want to do:

Open text file
Write, after the whats already there: variable blah blah.
Reply With Quote
  #2  
Old 06-09-2003, 11:04 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,745
Default

Open it for Append, not Output. Simple as that!
~MikeJ
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #3  
Old 06-09-2003, 11:08 PM
tHe LiNk tHe LiNk is offline
Newcomer
 
Join Date: Apr 2003
Posts: 15
Default

Thanks for the quick reply! Could you give me a quick example of the code?

Open App.Path & "\example.txt" For Append As #1
Write #1, example
Close #1

Would that work?
Reply With Quote
  #4  
Old 06-09-2003, 11:09 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,745
Default

Yes.

P.S.
Would post this reply faster, but only one post per minute so, ...
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #5  
Old 06-09-2003, 11:14 PM
tHe LiNk tHe LiNk is offline
Newcomer
 
Join Date: Apr 2003
Posts: 15
Default

Just one more question, what would be the best way to load all the individual entries into a list? Thanks for all the help so far, lifesaver dude!
Reply With Quote
  #6  
Old 06-09-2003, 11:20 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,745
Default

K. Use this little bit of code. (Assumes entries are delimited with spaces)
Code:
'==VARIABLE DECLARES== Dim ff as integer dim tempbin as string Dim sArray() as string Dim x as long ff = FreeFile Open "file.txt" For Output as #ff 'open Print #ff, tempbin 'save Close #ff 'close sArray = Split(tempbin, " ") 'splits on every space For x = 0 to ubound(sArray) List1.AddItem sArray(x) Next
That ought to do it for you!
~MikeJ
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #7  
Old 06-09-2003, 11:37 PM
tHe LiNk tHe LiNk is offline
Newcomer
 
Join Date: Apr 2003
Posts: 15
Default

Thanks for everything, i'll have a go at this as soon as i get on my vb computer. One more thing though (im really into this now ). How do i open the browsing window so the user can browse text files?
Reply With Quote
  #8  
Old 06-10-2003, 12:58 AM
tHe LiNk tHe LiNk is offline
Newcomer
 
Join Date: Apr 2003
Posts: 15
Default

I fixed that problem above myself. Need help with this now. Heres the code:

Code:
' Create a file Private sub create_click() Open App.Path & "\" + game.Text + ".txt" For Append As #1 Write #1, game.Text, developer.Text, publisher.Text, genre.Text, release.Text Close #1 End Sub ' Open the file (from using common dialog) Private Sub open_Click() Open filename.Text For Output As #1 Print #1, game.Text, developer.Text, publisher.Text, genre.Text, release.Text Close #1 End sub

For some reason, nothing happens when i click open...it creates the file alright. Just cant load the stuff into all the textboxes.
Reply With Quote
  #9  
Old 06-10-2003, 09:31 AM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,745
Default

filename.text won't work because it is asking for the actual file name. So you need to copy and paste the code of where it is written to, and replace filename.Text with it.

~MikeJ
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #10  
Old 06-11-2003, 02:31 AM
tHe LiNk tHe LiNk is offline
Newcomer
 
Join Date: Apr 2003
Posts: 15
Default

Did that, said "bad file mode" and selected the "Print" line.
Reply With Quote
  #11  
Old 06-11-2003, 04:51 AM
anomaly's Avatar
anomaly anomaly is offline
Contributor
 
Join Date: Sep 2001
Location: Florida
Posts: 517
Default

im doing the same thing, mine works fine, here it is:

Code:
'Write to the binary file SaveData = Text1.Text Open App.Path & "\Data\Test.dat" For Binary Access Read Write As FreeFile Put #FreeFile - 1, , StrData Close FreeFile - 1 Text1.Text = "" 'Save to the binary file Open App.Path & "\Data\Test.dat" For Binary Access Read Write As FreeFile StrData = String(LOF(FreeFile - 1), " ") Get #FreeFile - 1, , StrData Close FreeFile - 1
__________________
So let it be written. So let it be run.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation Problem - PLs help urgenlty dpdsouza Installation / Documentation 4 12-02-2004 07:09 PM
Doesn't want to register! MikeyM Installation / Documentation 5 03-02-2003 08:22 PM
Writing or Saving String to Text File Cassie Word, PowerPoint, Outlook, and Other Office Products 4 02-06-2003 08:27 PM
Saving info from a text box as the name of a file? Thal General 12 01-15-2003 02:07 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->