LocationTextFieldParser.ErrorLine SyntaxDim fileParser As FileIO.TextFieldParser ' ...later... Dim result As String = fileParser.ErrorLine DescriptionThe ErrorLine property returns the contents of the most recent data input line that could not be parsed by the TextFieldParser object. Failed parsing is indicated by the Microsoft.VisualBasic.FileIO.MalformedLineException exception being thrown during a read operation. The ErrorLineNumber property returns the numeric line position of the errant line. Usage at a Glance
ExampleThe following code imports a comma-delimited file, monitoring the input for errors. Dim oneLine( ) As String Dim inputFile As New FileIO.TextFieldParser("c:\temp\data.txt") inputFile.SetDelimiters(",") Try Do While Not inputFile.EndOfData oneLine = inputFile.ReadFields( ) ' ----- Process data here... Loop Catch ex As FileIO.MalformedLineException ' ----- Bad data. MsgBox("Bad data found at line " & inputFile.ErrorLineNumber & _ ":" & vbCrLf & vbCrLf & inputFile.ErrorLine & vbCrLf & _ vbCrLf & "Processing aborted.") Finally inputFile.Close( ) End Try Related Framework Entries
See AlsoEndOfData Property, ErrorLineNumber Property, LineNumber Property, ReadFields Method, TextFieldParser Object |