Syntax
|
Width#
filenumber,newwidth
|
Description
|
Specifies the line width for sequential files opened in either
Output
or
Append
mode.
|
Comments
|
The
Width#
statement requires the following parameters:
|
|
Parameter
|
Description
|
|
filenumber
|
Integer used by the Basic Control Engine to refer to the open file—the number passed to the
Open
statement.
|
|
newwidth
|
Integer between 0 to 255 inclusive specifying the new width. If newwidth is 0, then no maximum line length is used.
|
|
When a file is initially opened, there is no limit to line length. This command forces all subsequent output to the specified file to use the specified value as the maximum line length.
The
Width
statement affects output in the following manner: if the column position is greater than 1 and the length of the text to be written to the file causes the column position to exceed the current line width, then the data is written on the next line.
The
Width
statement also affects output of the
Print
command when used with the
Tab
and
Spc
functions.
|
Example
|
This statement sets the maximum line width for file number 1 to 80 columns.
Const crlf$ = Chr$(13) + Chr$(10)
Sub Main()
Dim i,msg1,newline$
Open "test.dat" For Output As #1 'Create data file.
For i = 0 To 9
Print #1,Chr(48 + i); 'Print 0-9 to test file all on same line.
Next i
Print #1,crlf 'New line.
Width #1,5 'Change line width to 5.
For i = 0 To 9 'Print 0-9 again. This time, five characters print before line wraps.
Print #1,Chr(48 + i);
Next I
Close #1
msg1 = "The effect of the Width statement is as shown below: " & crlf
Open "test.dat" For Input As #1 'Read new file.
Do While Not Eof(1)
Input #1,newline$
msg1 = msg1 & crlf$ & newline$
Loop
Close #1
msg1 = msg1 & crlf$ & crlf$ & "Choose OK to remove the test file."
MsgBox msg1 'Display effects of Width.
Kill "test.dat"
End Sub
|
See Also
|
Print (statement); Print# (statement); Tab (function); Spc (function)
|