Width # Statement

See AlsoC2RG5K              ExampleG87JT3>Low

Assigns an output-line width to a file.


Width # filenumber, width


The Width # statement has these parts:

Part               Description


filenumber      Number used to open the file with the Open statement.  It can be any numeric expression71RISN that evaluates to the number of an open file.  Note that the number sign (#) preceding filenumber is not optional.

width             Numeric expression in the range 0 to 255, inclusive, that indicates how many characters appear on a line before a new line is started.  If width equals 0, there is no limit to the length of a line.  The default value for line width is 0.


The Width # statement permits output-line width to be changed in files that are already open.

See Also

Open Statement103I7PS

Print # Statement12JHDL9

Width Statement Example

The example uses the Width statement to set the output-line width for a file.  A test file is created, and the same characters are written to two different line widths.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim I, Msg, NL, Text                  ' Declare variables.

   NL = Chr(10)                          ' Define newline.

   Open "TESTFILE" For Output As #1      ' Create sample data file.

   For I = 0 To 9                        ' Print ASCII characters

      Print #1, Chr(48 + I);             ' 0-9 to test file

   Next I                                ' all on same line.

   Print #1,                             ' Start new line.

   Width #1, 5                           ' Change line width to 5.

   For I = 0 To 9                        ' Print 0-9 again. This

      Print #1, Chr(48 + I);             ' time, five characters print

   Next I                                ' before line wraps.

   Close #1                              ' Close file.

   Msg = "The effect of the Width statement is as shown below: " & NL

   Open "TESTFILE" For Input As #1       ' Reopen the file for input.

   Do While Not Eof(1)

      Input #1, Text                     ' Get lines from file.

      Msg = Msg & NL & Text              ' Create message.


   Close #1                              ' Close file.

   Msg = Msg & NL & NL & "Choose OK to remove the test file."

   MsgBox Msg                            ' Display effects of Width.

   Kill "TESTFILE"                       ' Remove test file from disk.

End Sub