TextFieldParser.ErrorLineNumber Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the number of the line that caused the most recent MalformedLineException exception.
public:
property long ErrorLineNumber { long get(); };
public long ErrorLineNumber { get; }
member this.ErrorLineNumber : int64
Public ReadOnly Property ErrorLineNumber As Long
Property Value
The number of the line that caused the most recent MalformedLineException exception.
Examples
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
Remarks
If no MalformedLineException exceptions have been thrown, -1 is returned.
The ErrorLine property can be used to display the number of the line that caused 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.
To | See |
---|---|
Read from a delimited file | How to: Read From Comma-Delimited Text Files |
Read from a fixed-width file | How to: Read From Fixed-width Text Files |
Applies to
See also
- OpenTextFieldParser(String)
- Objects (Visual Basic)
- Parsing Text Files with the TextFieldParser Object
- How to: Read From a Text File with Multiple Formats in Visual Basic
- How to: Read From a Fixed-width Text File in Visual Basic
- How to: Read From a Comma-Delimited Text File in Visual Basic
- Try...Catch...Finally Statement (Visual Basic)