TextFieldParser.ErrorLineNumber Property
Returns the number of the line that caused the most recent MalformedLineException exception.
' Usage
Dim value As Long = TextFieldParserObject.ErrorLineNumber
' Declaration
Public ReadOnly Property ErrorLineNumber As Long
Property Value
Long.
Exceptions
This property throws no exceptions.
Remarks
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.
Tasks
The following table lists examples of tasks involving the ErrorLineNumber property.
To |
See |
---|---|
Read from a delimited file |
How to: Read From Comma-Delimited Text Files in Visual Basic |
Read from a fixed-width file |
Example
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
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.ErrorLineNumber & " is not valid.")
End Try
End While
Requirements
Namespace:Microsoft.VisualBasic.FileIO
Class:TextFieldParser
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Permissions
No permissions are required.
See Also
Tasks
How to: Read From Text Files with Multiple Formats in Visual Basic
How to: Read From Fixed-width Text Files in Visual Basic
How to: Read From Comma-Delimited Text Files in Visual Basic
How to: Test Code with a Try…Catch Block in Visual Basic
Concepts
Parsing Text Files with the TextFieldParser Object