Q(uick)BASIC Statement: WIDTH
Quick View
WIDTH
A file I/O statement that assigns an output-line width to a file or device or changes the number of columns and lines displayed on the screen
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- WIDTH [columns%] [,rows%]
- WIDTH {#filenumber% | device$}, columns%
- WIDTH LPRINT columns%
Description/Parameter(s)
columns% | The desired width in columns. Screen display width must be 40 or 80 columns. |
rows% | The desired screen-display height in rows. The value can be 25, 30, 43, 50, or 60, depending on your display adapter and screen mode. |
#filenumber% | The number of an open file or device. |
device$ | The name of a device:
|
Example
OPEN "LPT1:" FOR OUTPUT AS #1
WIDTH #1, 132
See also:
Syntax
- WIDTH [columns][,lines]
- WIDTH {#filenumber | device},width
- WIDTH LPRINT width
Description/Parameter(s)
Both files and devices can be assigned an output-line width.
Syntax | Description |
WIDTH [columns][,lines] | Sets the number of columns and lines to display on the screen. |
The value of columns must be either 40 or 80. The default value is 80. | |
The value of lines may be 25, 30, 43, 50, or 60, depending on the display adapter used and the screen mode (see the SCREEN statement help topic for more information). The number of lines displayed when the program started will determine the default value. | |
WIDTH #filenumber,width | Sets the line width of an output device opened as a file (for example, LPT1: or CONS:). |
The filenumber argument is the number associated with the file in the OPEN statement. | |
This form permits altering the width while a file is open, since the statement takes place immediately. | |
WIDTH device,width | Sets the line width of device (a device file name). |
The device should be a string expression (for example, "CONS:"). | |
Note that this width assignment is deferred until the next OPEN statement affecting the device; the assignment does not affect output for an already open file. | |
WIDTH LPRINT width | Sets to width the line width of the line printer, for use by subsequent LPRINT statements. |
Example
In the following example, the record width for file #1 (the printer) is set to different widths (the sample output also refers to a printer):
'*** Programming example that uses WIDTH ***
OPEN "LPT1:" FOR OUTPUT AS #1
Test$ = "1234567890"
WIDTH #1, 3
PRINT #1, Test$
WIDTH #1, 4
PRINT #1, Test$
CLOSE
Sample Output:
123 456 789 0 1234 5678 90See also:
Syntax
- WIDTH {#filenumber% | device$}, width%
- WIDTH LPRINT width%
- WIDTH {screenwidth% | ,screenheight% | screenwidth%, screenheight}
Description/Parameter(s)
#filenumber% | Identifies an output device for which to change the output-line width. |
device$ | A string expression with the value
|
screenwidth% | The maximum number of text characters per line on the display screen; an integer expression with a value of 40 or 80 (default is 80). |
screenheight% | The maximum number of text lines on the screen; a numeric expression with an integer value of
|
width% | For WIDTH, the width of the output-line for the file or device. For WIDTH LPRINT an integer value between 1 and 255 (default is 80). A carriage return and line feed will be sent to the printer after this number of characters is printed in a line. |
Not all of the argument values are valid in every case; it depends on the installed display adapter and the screen mode established by the most recently executed SCREEN statement. |
- The WIDTH #filenumber%, width% form:
- Sets the line width of an output device already opened as a file (for example, LPT1: or CONS:).
- The argument filenumber% is the file number associated with the device through the OPEN statement.
- The "#" character in front of filenumber% is not optional.
- The width assignment takes place immediately.
- The WIDTH device$, width% form:
- Sets to width% the line width of device$ (a device filename). The device should be a string expression (for example, "LPT1:").
- The width assignment is deferred until the next OPEN statement affecting the device.
- The assignment does not affect output for an already open device.
- The WIDTH LPRINT width% form:
- Sets the line width of the line printer for use by subsequent LPRINT statements.
- Equivalent to the statement form: WIDTH "LPT1:", width
- The WIDTH {screenwidth% | ,screenheight% | screenwidth%, screenheight} form:
- Sets the number of text character columns and lines to display on the screen.
- The value of screenwidth% must be either 40 or 80; default is 80.
- The value of screenheight% may be 25, 30, 43, 50, or 60, depending on the display adapter used and the screen mode.
- The number of lines that can be displayed when the program is started are listed below:
Adapter 1 Screen mode 2 Screenwidth x screenheight Color display MDPA 0 80x25 Monochrome Hercules 0 80x25 Monochrome 3 80x25 Monochrome CGA 0 40x25, 80x25 Color 1 40x25 Color 2 80x25 Color EGA 0 40x25, 40x43, 80x25, 80x43 Color 0 40x25, 40x43, 80x25, 80x43 Enhanced color 0 40x25, 40x43, 80x25, 80x43 Monochrome 1 40x25 Color or Enhanced color 2 80x25 Color or Enhanced color 7 40x25 Color or Enhanced color 8 80x25 Color or Enhanced color EGA 9 80x25, 80x43 Enhanced color EGA or VGA 10 80x25, 80x43 Monochrome VGA 0 40x25, 40x43, 40x50 Analog 0 80x25, 80x43, 80x50 Analog 1 40x25 Analog 2 80x25 Analog 7 40x25 Analog 8 80x25 Analog 9 80x25, 80x43 Analog 10 80x25, 80x43 Analog 11 80x30, 80x60 Analog 12 80x30, 80x60 Analog 13 40x25 Analog MCGA 0 40x25, 80x25 Color or Analog 1 40x25 Color or Analog 2 80x25 Color or Analog 11 80x30, 80x60 Analog 13 40x25 Analog - 1 See ⮜ SCREEN Statement ⮞ for a description of the different adapters.
- 2 Screen mode 4 has a screen width and screen height of 80x25 in text format. For a list of the computers supported by BASIC screen mode 4, see the ⮜ SCREEN Statement ⮞.
Example
This example uses the WIDTH statement to set different widths for file #1 (a terminal on COM1; the sample output shown below also refers to a printer or terminal attached to COM1).
CLS
'Open the port at the proper baud rate
OPEN "COM1:9600,N,8,1,ASC,LF" FOR OUTPUT AS #1
'Set Up a test string
Test$ = "1234567890"
'Change width to 3
WIDTH #1, 3
PRINT #1, Test$
'Change width to 4
WIDTH #1, 4
PRINT #1, Test$
'Delay 3 seconds so you can observe the results on the terminal.
SLEEP 3
'Close the file
CLOSE #1
Sample Output:
123 456 789 0 1234 5678 90See also: