FieldWidths Property

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)

public int[] FieldWidths { get; set; }

Property Value

Type: System.Int32[]
Integer ().

For more detailed information, see the Visual Basic topic TextFieldParser.FieldWidths Property.

This property is meaningful only if TextFieldParser.TextFieldType Property = 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. For more information, see TextFieldParser.SetFieldWidths Method.

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 = New Integer() {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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2016 Microsoft