This documentation is archived and is not being maintained.

TextFieldParser.ErrorLineNumber Property

Note: This property is new in the .NET Framework version 2.0.

Returns the number of the line that caused the most recent MalformedLineException exception.

Namespace: Microsoft.VisualBasic.FileIO
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public long ErrorLineNumber { get; }
/** @property */
public long get_ErrorLineNumber ()

public function get ErrorLineNumber () : long

Property Value


For more detailed information, see the Visual Basic topic TextFieldParser.ErrorLineNumber Property.

If no MalformedLineException exceptions have been thrown, -1 is returned.

The TextFieldParser.ErrorLine Property can be used to display the number of the line causing the exception. Blank lines and comments are not ignored when determining the line number.

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

This example uses the ErrorLineNumber property to display the location of 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
        currentRow = FileReader.ReadFields
        For Each currentField As String In currentRow
            My.Computer.FileSystem.WriteAllText _
            ("C://testfile.txt", currentField, True)
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & FileReader.ErrorLineNumber & " is not valid.")
    End Try
End While

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0