list
Works great! But, what is the 'List' object for? It doesn't seem to do anything. Thanks.
Public Sub WriteCSVfile() Try 'A TextReader is use to read character from a byte in a particular encoding Dim stReader As StreamReader = New System.IO.StreamReader(File.OpenRead("c:\CSV\Testing.csv")) 'It initialize the instance of List(of String) class that has the default initial capacity Dim strList As New List(Of String)() 'It validates whether the particular file is already exist If File.Exists("c:\CSV\TestingOut.csv") Then 'Deleting the file File.Delete("c:\CSV\TestingOut.csv") End If 'For the specified file, you have to initialize a new instance of the StreamWriter class 'for encoding and buffering the size Dim stWriter As New StreamWriter("c:\CSV\TestingOut.csv") 'Declare an empty string variable Dim str As String = String.Empty While stReader.Peek() >= 0 Dim strline As String = stReader.ReadLine() Dim strvalues As String() = strline.Split(";"c) strList.Add(strvalues(0)) str = str + strline + Chr(10) End While 'It will close the StreamReader object and the underlying stream 'It releases any system resources associate the reader stReader.Close() 'It will write a string to the stream stWriter.Write(str) 'It will close the current object and the underlying stream stWriter.Close() Catch ex As Exception 'Catching errors MessageBox.Show(ex.Message) End Try End Sub
click event handler
of it and do the following codes for reading and writing CSV file in the specified path when the button is clicked.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click WriteCSVfile() End Sub