This documentation is archived and is not being maintained.

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 */
public int[] get_FieldWidths ()

/** @property */
public void set_FieldWidths (int[] value)

public function get FieldWidths () : int[]

public function set FieldWidths (value : int[])

Not applicable.

Property Value

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.



Read from a fixed-width text file

How to: Read From a Fixed-width Text File 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 _
    MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.FixedWidth
    MyReader.FieldWidths = New Integer() {5, 10, 11, -1}
    Dim currentRow As String()
    While Not MyReader.EndOfData
            currentRow = MyReader.ReadFields()
            Dim currentField As String
            For Each currentField In currentRow
        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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0