Share via


TextFieldParser.EndOfData Property

Returns True if there are no non-blank, non-comment lines between the current cursor position and the end of the file.

' Usage
Dim value As Boolean = TextFieldParserObject.EndOfData
' Declaration
Public ReadOnly Property EndOfData As Boolean

Property Value

Boolean.

Remarks

This property can be used when reading from files to determine the end of the data being read.

Tasks

The following table lists examples of tasks involving the EndOfData 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

How to: Read From Fixed-width Text Files in Visual Basic

Example

This example uses the EndofData property to loop through all the fields in the file with the TextFieldReader, FileReader.

Dim StdFormat As Integer() = {5, 10, 11, -1}
Dim ErrorFormat As Integer() = {5, 5, -1}
Using FileReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\testfile.txt")
    FileReader.TextFieldType = FileIO.FieldType.FixedWidth
    FileReader.FieldWidths = StdFormat
    Dim CurrentRow As String()
    While Not FileReader.EndOfData
        Try 
            Dim RowType As String = FileReader.PeekChars(3)
            If String.Compare(RowType, "Err") = 0 Then 
                ' If this line describes an error, the format of the row will be different.
                FileReader.SetFieldWidths(ErrorFormat)
                CurrentRow = FileReader.ReadFields
                FileReader.SetFieldWidths(StdFormat)
            Else 
                ' Otherwise parse the fields normally
                CurrentRow = FileReader.ReadFields
                For Each newString As String In CurrentRow
                    My.Computer.FileSystem.WriteAllText("newFile.txt", newString, True)
                Next 
            End If 
        Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
            MsgBox("Line " & ex.Message & " is invalid.  Skipping")
        End Try 
    End While 
End Using

Requirements

Namespace:Microsoft.VisualBasic.FileIO

Class:TextFieldParser

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

Permissions

The following permissions are required:

Permission

Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

SecurityPermission

Describes a set of security permissions applied to code. Associated enumeration: ControlEvidence.

For more information, see Code Access Security and Requesting Permissions.

See Also

Reference

TextFieldParser Object

TextFieldParser.EndOfData