ErrorLine Property


ErrorLine Property

Location

TextFieldParser.ErrorLine

Syntax

     Dim fileParser As FileIO.TextFieldParser     ' ...later...     Dim result As String = fileParser.ErrorLine 

Description

The 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

  • This property is read-only.

  • In the absence of malformed line errors, this property returns an empty string.

  • You must close the TextFieldParser object when finished with it. Use the object's Close method or create the object instance with the Using keyword. See the TextFieldParser Object entry in this chapter for an example.

Example

The 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

  • Microsoft.VisualBasic.FileIO.TextFieldParser.ErrorLine Property

See Also

EndOfData Property, ErrorLineNumber Property, LineNumber Property, ReadFields Method, TextFieldParser Object




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net