Export (0) Print
Expand All

TextFieldParser.ErrorLine Property 

Returns the line that caused the most recent MalformedLineException exception.


' Usage
Dim value As String = TextFieldParserObject.ErrorLine
' Declaration
Public ReadOnly Property ErrorLine As String

String.

If no MalformedLineException exceptions have been thrown, an empty string is returned.

The TextFieldParser.ErrorLineNumber Property can be used to display the number of the line causing the exception.

The following table lists examples of tasks involving the ErrorLine property.

This example uses the ErrorLine property to display the line causing the current MalformedLineException exception.

Dim FileReader As Microsoft.VisualBasic.FileIO.TextFieldParser
FileReader = My.Computer.FileSystem.OpenTextFieldParser("C:\test.txt")
Dim currentRow As String()
While Not FileReader.EndOfData
    Try
        currentRow = FileReader.ReadFields
        For Each currentField As String In currentRow
            My.Computer.FileSystem.WriteAllText _
            ("C://testfile.txt", currentField, True)
        Next
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & FileReader.ErrorLine & " is not valid.")
    End Try
End While

Namespace: Microsoft.VisualBasic.FileIO

Class: TextFieldParser

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

No permissions are required.

Community Additions

ADD
Show:
© 2014 Microsoft