Dim ffile as integer
ffile = freefile 'get a free file number
Open "Textfile.txt" for append as #ffile 'open file for append
print #ffile,txtend.text 'write the contents to the file
close #ffile 'close the file
Alternately, you can perform the same task in Binary mode.
I hope David doesn't mind if I use some of his code....
[tt]
Dim ffile as integer
ffile = freefile 'get a free file number
Open "Textfile.txt" for Binary as #ffile 'open file
Put #ffile, Lof(ffile)+1, txtend.text 'write the contents
close #ffile 'close the file
[/tt]
This just adds the contents of txtend.text to "Textfile.txt" starting at one byte after the end of the existing file: Lof(ffile)+1.
The advantage here is that you don't have to close the file and then re-open it in a different mode in order to perform additional manipulations. From this point, you can read the entire file into a text or list box, search for strings in the file, modify the contents and write back to the file without ever closing it.
A lot more versatile than simply allowing you to add a line to the end of the file.
In most cases binary file manipulation is the way to go. One reason is that it is several times faster. You don't need to read and write individual lines of data from a For/Next or Do Loop: you can read or write an entire file in one operation. Another reason is that it doesn't care what type of file you are working with (try reading Win386.swp after opening it For Input).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.