Free Visual Basic 2010 Source Code VB2010
How to Read data from a CSV File








HOW TO READ DATA FROM A CSV FILE USING VISUAL BASIC 2010 (VB 2010)


DESCRIPTION

This free Visual Basic 2010 VB2010 code is a simple source code example of reading data from a CSV file using Visual Basic 2010.


THE VISUAL BASIC 2010 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 MyCSVReader As System.IO.StreamReader
Public Line_Count As Integer
Public MyData1(1000) As String
Public MyData2(1000) As String
Public MyData2(1000) As String


THE FREE VISUAL BASIC 2010 VB 2010 SOURCE CODE

Copy and Paste this Visual Basic 2010 code wherever you need it:

'.....Free Source Code from www.freevb2010code.com
'.....Define a StreamReader that we can use to read the CSV file
'.....Note that MyFileName should include the path to be safe
MyFileName="c:\myfile.csv"
MyCSVReader = My.Computer.FileSystem.OpenTextFileReader(MyFileName)
Line_Count = -1
'.....Start the count at -1 so the first record is 0
Do While Not MyCSVReader.EndOfStream '.....Repeat until no more data
Line_Count = Line_Count + 1
'.....Increment the record counter
'.....Define an array created from the CSVReader data, splitting up the line at each comma - NOTE any character can be used if desired not just a comma. But it must match the file format used!
Dim MyFieldInput() As String = Split(MyCSVReader.ReadLine, ",")
MyData1(Line_Count) = MyFieldInput(0)
'.....Assign the first data
MyData2(Line_Count) = MyFieldInput(1) '.....Assign the second data
MyData3(Line_Count) = MyFieldInput(2) '.....Assign the third data
Loop
MyCSVReader.Close()
'.....Close the StreamReader





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 Visual Basic 2010 code shows a simple method on how to read from a csv file using Visual Basic 2010.





counter
Free Visual Basic 2010 Source Code VB2010 How to Read data from a CSV File we hope you find this example useful for Visual Basic 2010 programming