This documentation is archived and is not being maintained.

TextFieldParser.SetFieldWidths Method

Visual Studio 2008

Updated: July 2008

Sets the delimiters for the reader to the specified values.

' Usage
TextFieldParserObject.SetFieldWidths(fieldWidths)
' Declaration
Public Sub SetFieldWidths( _
   ByVal fieldWidths As Integer() _
)

fieldWidths

Array of Integer.

The following condition may cause an exception to be thrown:

The existing contents of the Delimiters property are cleared when this is set.

This method provides a way to set delimiters without creating an array.

The following table lists example of tasks involving the SetFieldWidths method.

This example opens a text-field parser and defines the field width as 5.

Using FileReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\logs\test.log")
    FileReader.SetFieldWidths(5)
End Using

Replace the path C:\logs\test.log with the path and name of the file you wish to parse.

The following example opens a text-field parser and defines the field widths as 5, 10, and variable.

Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\logs\test.log")
    MyReader.SetFieldWidths(5, 10, -1)
End Using

Replace the path C:\logs\test.log with the path and name of the file you wish to parse.

Namespace: Microsoft.VisualBasic.FileIO

Class: TextFieldParser

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

No permissions are required.

Date

History

Reason

July 2008

Revised first sentence.

Customer feedback.

Show: