This topic has not yet been rated - Rate this topic

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

Boolean .

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

The following table lists examples of tasks involving the EndOfData property.

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


Namespace: Microsoft.VisualBasic.FileIO

Class: TextFieldParser

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

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.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ