Udostępnij za pośrednictwem


TextFieldParser.LineNumber Property

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

' Usage
Dim value As Long = TextFieldParserObject.LineNumber
' Declaration
Public ReadOnly Property LineNumber As Long

Property Value

Integer.

Remarks

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.

Example

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

Requirements

Namespace:Microsoft.VisualBasic.FileIO

Class:TextFieldParser

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

Permissions

No permissions are required.

See Also

Reference

TextFieldParser Object

TextFieldParser.LineNumber