Appending to files in VB

Appending to files in VB

If you write any text to the file using write method, the file will be overwritten. In order to append the text to the existing text the Append method is used. This code opens test.txt and adds a entry to the end of a file.

Dim nFileNum As Integer

‘ Get a free file number
nFileNum = FreeFile

‘ Open Test.txt for append
Open App.Path & “c:\test.txt” For Append As nFileNum

‘ Add the contents of TextBox1 to Test.txt
Print #nFileNum, TextBox1.Text

‘ Close the file
Close nFileNum

Thus the contents of TextBox1.Text is appended to the test.txt file.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.