Q(uick)BASIC Statement: WRITE

Quick View

WRITE

A device I/O statement that sends data to the screen

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • WRITE [[#]filenumber%,] expressionlist
Description/Parameter(s)
filenumber% The number of an open sequential file. If the file number is omitted, WRITE writes to the screen.
expressionlist One or more variables or expressions, separated by commas, whose values are written to the screen or file.
WRITE inserts commas between items and quotation marks around strings as they are written. WRITE writes values to a file in a form that can be read by the INPUT statement.
Example
CLS OPEN "LIST" FOR OUTPUT AS #1 DO INPUT " NAME: ", Name$ INPUT " AGE: ", Age$ WRITE #1, Name$, Age$ INPUT "Add another entry"; R$ LOOP WHILE UCASE$(R$) = "Y" CLOSE #1 'Print the file to the screen. OPEN "LIST" FOR INPUT AS #1 CLS PRINT "Entries in file:": PRINT DO WHILE NOT EOF(1) INPUT #1, Rec1$, Rec2$ 'Read entries from file. PRINT Rec1$, Rec2$ 'Print the entries on the screen. LOOP CLOSE #1 KILL "LIST"
Syntax
  • WRITE [expressionlist]
Description/Parameter(s)

If expressionlist is omitted, a blank line is written. If expressionlist is included, the values of the expressions are written to the screen. The expressions in the list may be numeric and/or string expressions. They must be separated by commas.

When the printed items are written, each item is separated from the last by a comma. Printed strings are delimited by quotation marks. After the last item in the list is printed, BASIC inserts a carriage-return-line-feed.

The WRITE statement writes numeric values without leading or trailing spaces.

Example

The following example shows the difference between the PRINT and WRITE statements:

'*** Example program that uses WRITE *** CLS 'clear the screen A=80 : B=90 : C$="That's all." : D=-1.0E-13 WRITE A,B,C$,D PRINT A,B,C$,D

Sample Output:

80,90,"That's all.",-1E-13 80 90 That's all. -1E-13
Syntax
  • WRITE (expressionlist)
Description/Parameter(s)
expressionlist Specifies one or more values to be written.
The values are written on the screen separated by commas, with double quotation marks around strings and no spaces around numbers.
If expressionlist is omitted, a blank line is written.

Usage Notes

  • If the argument expressionlist is omitted, a blank line is written. If expressionlist is included, the values of the expressions are written to the screen.
  • The expressions in the list may be numeric and/or string expressions. They must be separated by commas.
  • When the printed items are written, each item is separated from the last by a comma.
  • Printed strings are delimited by double quotation marks. After the last item in the list is printed, BASIC inserts a carriage-return- and-line-feed sequence.
  • The WRITE statement writes numeric values without leading or trailing spaces.
Example

This example shows how the WRITE statement outputs delimiters between data items.

CLS 'Clear the screen. A = 80: B = 90: C$ = "That's all.": D = -1E-13 WRITE A, B, C$, D PRINT A, B, C$, D

Sample Output:

80,90,"That's all.",-1E-13 80 90 That's all. -1E-13