Free Visual Basic 2008 Source Code VB2008
How to Read data from a CSV File








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


DESCRIPTION

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


THE VISUAL BASIC 2008 VB2008 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 2008 VB 2008 SOURCE CODE

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

'.....Free Source Code from www.freevisualbasic2008sourcecode.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 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 Visual Basic 2008 code example uselful. This Visual Basic 2008 code shows a simple method on how to read from a csv file using Visual Basic 2008.





counter