FieldWidths Property


FieldWidths Property

Location

TextFieldParser.FieldWidths

Syntax

     Dim fileParser As FileIO.TextFieldParser     ' ...later...     Dim result As Integer(  ) = fileParser.FieldWidths 

or:

     fileParser.FieldWidths = setOfWidths 


setOfWidths (required; Integer array)

An array of values, each of which indicates the character length of a positional field within a fixed-width text file being parsed by a TextFieldParser object. All field widths must be greater than zero, although the last array element may be less than or equal to zero to indicate a final variable-width field.

Description

The FieldWidths property sets or retrieves the number of characters used for each field in fixed-width text-file parsing. The first field begins with the first character on each record line, and subsequent fields immediately follow the fields before. You can indicate that the last field is of variable length (that is, it includes all characters until the end of the line) by setting the last field width to -1.

You can also set the field widths with the TextFieldParser object's SetFieldWidths method.

Usage at a Glance

  • The FieldWidths property is only useful with fixed-width input files, not delimited files.

  • Setting the FieldWidths property does not alter the current value of the TextFieldType property.

  • An exception is thrown if you assign a zero or negative value to any field width other than the last one.

  • You must close the TextFieldParser object when finished with it. Use the object's Close method or create the object instance with the Using keyword. See the TextFieldParser Object entry in this chapter for an example.

Example

The following example uses the FieldWidths property to indicate that each line in the input file contains three fields: a 3-character field, a 30-character field, and a 5-character field.

     Dim scanInput As Microsoft.VisualBasic.FileIO.TextFieldParser     ' ...later...     scanInput.TextFieldType = _        Microsoft.VisualBasic.FileIO.FieldType.FixedWidth     scanInput.FieldWidths = New Integer(  ) {3, 30, 5} 

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.TextFieldParser.FieldWidths Property

See Also

Delimiters Property, ReadFields Method, SetDelimiters Method, SetFieldWidths Method, TextFieldParser Object, TextFieldType Property




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net