LineNumber Property


LineNumber Property

Location

TextFieldParser.LineNumber

Syntax

     Dim fileParser As FileIO.TextFieldParser     ' ...later...     Dim result As Long = fileParser.LineNumber 

Description

The LineNumber property returns the 1-based current line number (the line about to be read) within the file being parsed by a TextFieldParser object. If the end of the file has been reached, this property returns -1.

Usage at a Glance

  • This property is read-only.

  • This property considers blank lines and comment lines. It is a line counter, not a record counter. This property may return a value other than -1 even when the object's EndOfData property returns true.

  • You must close the TextFieldParser object when finished with it. Use the object's Close method or create the object instance with the Using keyword. See the TextFieldParser Object entry in this chapter for an example.

Example

The following example looks for "EOF" as an end-of-file marker.

     Dim fileParser As FileIO.TextFieldParser     Dim oneLine(  ) As String     Dim lastLine As Long     Dim markerFound As Boolean = False     fileParser = New FileIO.TextFieldParser(dataFile)     fileParser.SetDelimiters(",")     Do While (fileParser.LineNumber <> -1)        lastLine = fileParser.LineNumber        oneLine = fileParser.ReadFields(  )        If (UCase(oneLine(0)) = "EOF") Then           MsgBox("Found EOF marker at line " & lastLine)           markerFound = True           Exit Do        End If     Loop     fileParser.Close(  )     If (markerFound = False) Then MsgBox("EOF marker not found.") 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.TextFieldParser.LineNumber Property

See Also

EndOfData Property, ErrorLineNumber Property, PeekChars Method, ReadFields Method, ReadLine Method, ReadToEnd Method, TextFieldParser Object




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net