Skip to content

Instantly share code, notes, and snippets.

@theorigin
Created July 30, 2013 15:08
Show Gist options
  • Save theorigin/6113797 to your computer and use it in GitHub Desktop.
Save theorigin/6113797 to your computer and use it in GitHub Desktop.
Parse CSV using Microsoft.VisualBasic.FileIO.TextFieldParser
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\testfile.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
MsgBox(currentField)
Next
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment