Contents |
Effect
Displays and formats text and numbers on the screen or sends formatted data to different devices through file handling.
Note: PRINT can be replaced by the "?" character. This will be expanded to "PRINT" when listing a MSX-BASIC program.
Syntax
PRINT #<FileNumber>, USING <ItemFormat>; <Item>;<Item>...
Parameters
<Item> can be a character string, an expression, a variable or a value to display or send. All four items types can be mixed freely.
Items must be separated by ";". If the last item does not end to ";" CR+LF combination is displayed or sent.
A comma can replace a ";" to separate the items. In case of "," they are separated by tabulator instead of a space.
<Item> can be omitted to display or send an empty line.
#<FileNumber>, is optional. <FileNumber> is a number between 0 and 15 that points to opened file name. Please see OPEN instruction.
USING <ItemFormat>; is optional. <ItemFormat> is a string that defines how the next items to be displayed or sent must be formatted. When USING is used the type of following usable items depends on the specified format.
The format string can contain following definitions:
Editor's note: Following table and comments are inaccurate and need revisiting. Please help.
Format definition | Data type | Description |
---|---|---|
! | String | Prints only first character of current item. Example:
PRINT USING "!";"United","Nations" UN |
\[n spaces]\ | String | Prints n + 2 characters. When the length of the data is less than n + 2 characters, the rest is padded with spaces. Example:
PRINT USING "\ \";"ABCDEF","GHI","JKLMN" ABCDGHI JKLM |
& | String | Displays the whole string. Example:
A$="North";B$="South":PRINT USING "& Pole ";A$,B$ North Pole South Pole |
# | Number | Reserves a space (up to 24) for number. Decimal point can be specified with the full stop ".". Example:
PRINT USING "POINT:###.#";123.4 POINT:123.4 When the amount of digits is smaller than the amount of specified #, the number is displayed with equal amounts of margins at both sides and when the number of digits is larger, a % is output. Example: 10 PRINT USING "####";12 20 PRINT USING "#####";12345 RUN 12 %12345 When the number of digits behind the decimal separator is smaller than the amount of the input, it is padded with a "0" and when it is larger, it is rounded to the nearest integer number. Example: 10 PRINT USING "##.##";25.3 20 PRINT USING "##.##";25.345 RUN 25.30 25.35 When displaying numeric data, the "+" sign is ignored and the character is counted as a number. 10 PRINT USING "###";+123 20 PRINT USING "###";-123 RUN 123 %-123 |
+ | Number | Positive numbers will be output with "+"-sign and negative numbers with a "-"-sign. Either in front or behind the number. Example:
10 PRINT USING "+####";123,-123 20 PRINT USING "####+";123,-123 RUN +123 -123 123+ 123- |
- | Number | Can be used to mark "-" to end of number when the number is negative. Example:
PRINT USING "###-";123,-123 123 123- |
** | Number | The space for numerical data will be filled with "*" characters. A single "*" represents a single digit.
10 PRINT USING "**######";123 20 PRINT USING "**######";-234 RUN *****123 ****-234 |
££ | Number | Displays "£" in front of number. One "£" layout symbol counts as digit.
10 PRINT USING "££###" ;1234 20 PRINT USING "+££###";-1234 RUN £1234 -£1234 |
**£ | Number | Displays "£" in front of number and fills up heading spaces with "*".
PRINT USING "**£###.##";12.34 ***£12.34 |
, | Number | Numbers will be printed in groups of 3 separated by "," |
^^^^ | Number | This in the end of definition will cause number to be printed in exponential format. |
Please note:" Format string should be used with caution. Pound signs should be avoided since this causes compatibility problem. On some machines this is "$" depending on local currency. "&" has been replaced with "\" on european and Brazilian machines causing easily "Type missmatch" error in localized machines. In Japanese machines "\" is printed as "¥"
Examples
10 FM$="The print documentation on & & has ##.#% relative accuracy" 20 PRINT USING FM$;"MRC",5 RUN
The print documentation on MRC has 5.0% relative accuracy Ok
PRINT USING "!!!";"Alpha";"Beta";"Charlie"
ABC Ok
Related to
CSRLIN, LOCATE, LPRINT, MAXFILES, OPEN, POS(), SCREEN, SPC(), TAB() , WIDTH
Compatibility
MSX-BASIC 1.0 or higher