Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TextFieldParser.FieldWidths Property

Denotes the width of each column in the text file being parsed.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
'Declaration
Public Property FieldWidths As Integer()

Property Value

Type: System.Int32()
An integer array that contains the width of each column in the text file that is being parsed.
ExceptionCondition
ArgumentException

A width value in any location other than the last entry of the array is less than or equal to zero.

This property is meaningful only if the TextFieldType property is set to FieldType.FixedWidth. If the last entry in the array is less than or equal to zero, the field is assumed to be of variable width.

The SetFieldWidths method can also be used to set field widths.

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

To

See

Read from a fixed-width text file

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

This example reads the file ParserText.txt, specifying the widths; the first column is 5 characters wide, the second is 10, the third is 11, and the fourth is of variable width

Using MyReader As New Microsoft.VisualBasic.FileIO.
    TextFieldParser("C:\ParserText.txt")

    MyReader.TextFieldType = 
        Microsoft.VisualBasic.FileIO.FieldType.FixedWidth
    MyReader.FieldWidths = {5, 10, 11, -1}
    Dim currentRow As String()
    While Not MyReader.EndOfData
        Try
            currentRow = MyReader.ReadFields()
            Dim currentField As String 
            For Each currentField In currentRow
                MsgBox(currentField)
            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.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.