Free Visual Basic 2008 Source Code VB2008
How to Write to a Text TXT File








HOW TO WRITE TO A TEXT FILE USING VISUAL BASIC 2008 (VB 2008)


DESCRIPTION

This Visual Basic 2008 code is a simple source code example of writing to a TEXT file using Visual Basic 2008 (VB2008).


THE VB 2008 SETUP

Add the following lines to your 'Module1' code (add the Imports as the first lines above Module1 - ie at the very top!)

Imports System
Imports System.IO
Imports System.Collections

Module 1:
Public MyTXTWriter As System.IO.StreamWriter
Public MyFileName As String
Public MyNewLine As String
Public MyText1 As String
Public MyText2 As String
Public MyText3 As String


THE FREE VISUAL BASIC 2008 SOURCE CODE

Copy and Paste this code wherever you need it:

'.....Free VB2008 Source Code from www.freevisualbasic2008sourcecode.com
'.....Note that MyFileName should include the path
MyFileName="c:\myfile.txt"
'.....Open the file
'.....Note that the second parameter specifies the Append Mode - ie True = Append, False = Overwrite
MyCSVWriter = My.Computer.FileSystem.OpenTextFileWriter(MyFileName, True)
'.....Now create the line(s) of text to be written to the TEXT file (ASSIGN TEXT)
MyNewLine = "This is my line of text"
'.....Write the line of data (WRITE TEXT)
MyTXTWriter.WriteLine(MyNewLine)
'.....Repeat the two lines of code above (assign text and write text) as many times as needed or loop etc.
'.....Close the file
MyTXTWriter.Close()





Home to FreeVisualBasic2008SourceCode.com
How to write to a CSV file
How to write to a TEXT file
How to read from a CSV file
How to read from a TEXT file
How to find a User Name
How to fill a ListView
How to write a ListView data table to a CSV file
How to call another program
How to copy and paste to the Windows Clipboard
How to concatenate (join) text
How to sort and Array


Copyright SGDesigns (c)2010

Our aim is to provide simple concise and easy to follow Free Visual Basic 2008 Source Code for the casual programmer in VB2008. We hope you find the VB2008 code example uselful. This VB 2008 code shows a simple method of how to write to a text file using Visual Basic 2008.





counter