Free Visual Basic 2010 Source Code VB2010
How to Write to a CSV File








HOW TO WRITE TO A CSV FILE USING VISUAL BASIC 2010 (VB2010)


DESCRIPTION

This VB2010 code is a simple source code example of writing to a CSV file using Visual Basic 2010.


THE VB2010 SETUP

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

Imports System
Imports System.IO
Imports System.Collections

Module1:
Public MyCSVWriter 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 SOURCE CODE

Copy and Paste this code wherever you need it:

'.....Free Source Code from www.freevb2010code.com
'.....Note that MyFileName should include the path
MyFileName="c:\myfile.csv"
'.....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 data to be written to the CSV file using "," to add commas between each data (ASSIGN CSV DATA)
MyText1="Data1"
MyText2="Data2"
MyText3="Data3"
MyNewLine = MyText1 + "," + MyText2 + "," + MyText3

'.....Write the line of data (WRITE CSV DATA)
MyCSVWriter.WriteLine(MyNewLine)

'.....Repeat the two lines of code above (assign csv data and write csv data) as many times as needed or loop etc. '.....Close the file
MyCSVWriter.Close()




Home to freevb2010code.com
VB2010 How to write to a CSV file
VB2010 How to write to a TEXT file
VB2010 How to read from a CSV file
VB2010 How to read from a TEXT file
VB2010 How to find a User Name
VB2010 How to fill a ListView
VB2010 How to write a ListView data table to a CSV file
VB2010 How to call another program
VB2010 How to copy and paste to the Windows Clipboard
VB2010 How to sort an array
VB2010 How to concatenate / join strings / text


Copyright SGDesigns (c)2010

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





counter