Export (0) Print
Expand All

TextFieldParser.LineNumber Property

Returns the current line number, or returns -1 if no more characters are available in the stream.

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

member LineNumber : int64 with get

Property Value

Type: System.Int64
The current line number.

This is an advanced member; it does not show in IntelliSense unless you click the All tab.

Blank lines and comments are not ignored when determining the line number.

This example searches for the name "Jones" in the text file and reports what line(s) it occurs on.

Using FileReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\ParserText.txt")
    FileReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
    FileReader.Delimiters = New String() {","}
    Dim currentRow As String()
    While Not FileReader.EndOfData
        Try
            currentRow = FileReader.ReadFields()
            Dim currentField As String 
            For Each currentField In currentRow
                If currentField = "Jones" Then
                    MsgBox("The name Jones occurs on line " & 
                    FileReader.LineNumber)
                End If 
            Next 
        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
            MsgBox("Line " & ex.Message & 
           "is not valid and will be skipped.")
        End Try 
    End While 
End Using

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft