Friday, October 24, 2008

Read .CSV file by Visual Basic

To run this code do following steps :
1) VS2005 or later should be installed.
2)Create Windows Application
3) Add a List box , Text box and a Button to you Form.
4) Go to the Code file
5)Replace the code with the following code
5)Debug
6)In Text Box write the location of the file (.csv)
7)hit the button
8) Enjoy
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim _str_arr As String
Dim _path As String
Dim _comma As String
Dim _temp As String
Dim _Read As System.IO.StreamReader
Dim i As Integer
Dim r As Integer
_path = TextBox1.Text
_Read = File.OpenText(_path)
_str_arr = _Read.ReadToEnd()
_Read.Close()
i = 0
While i < _str_arr.Length
_comma = ","
r = _str_arr.IndexOf(_comma)
_temp = _str_arr.Substring(i, r - i)
_str_arr = _str_arr.Remove(i, r - i + 1)
ListBox1.Items.Add(_temp)
End While
End Sub
end class



Contributor : sid_kuku@yahoo.com

2 comments:

Ekta said...

good stuff...
finally, a blog which is useful.. :)
carry on...

Sid Kuku said...

hehehe
gud 1.