Promote Your Blog
Google

Friday, March 2, 2012

How To Count Number of Records In A .csv File

You are right!!! Just put a counter inside the while loop reading .csv file row by row i.e.

Dim ir As Integer = 0

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(fn)

MyReader.TextFieldType = FileIO.FieldType.Delimited

MyReader.SetDelimiters(",")

Dim currentRow As String()

While Not MyReader.EndOfData

Try

currentRow = MyReader.ReadFields()

ir = ir + 1

Catch ex As Microsoft.VisualBasic.

FileIO.MalformedLineException

MsgBox("Line " & ex.Message &

"is not valid and will be skipped.")

End Try

End While

End Using

No comments:

Post a Comment