Difference between revisions of "PRINT"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
Line 8: Line 8:
 
{{PageDescription}}
 
{{PageDescription}}
 
* {{Parameter|expression}} is a numeric or string expression to be printed.
 
* {{Parameter|expression}} is a numeric or string expression to be printed.
** {{KW|SPC}}({{Parameter|n%}}) - specifies that {{Parameter|n%}} space characters will be printed.
+
** {{KW|SPACE$}}({{Parameter|n%}}) or {{KW|SPC}}({{Parameter|n%}}) - specifies that {{Parameter|n%}} space characters will be printed.
 
** {{KW|TAB}}({{Parameter|column%}}) - specifies that the print cursor is to move to column number {{Parameter|column%}}. If the print cursor is beyond that column, it is moved to that column on the next line.
 
** {{KW|TAB}}({{Parameter|column%}}) - specifies that the print cursor is to move to column number {{Parameter|column%}}. If the print cursor is beyond that column, it is moved to that column on the next line.
 +
** PRINT can also use the + '''concatenation''' operator to combine string values only.
 
* {{Parameter|separator}} is used to separate multiple expressions and specifies how the print cursor is to be moved before printing the next expression. It can be one of the following:
 
* {{Parameter|separator}} is used to separate multiple expressions and specifies how the print cursor is to be moved before printing the next expression. It can be one of the following:
 
** semi-colon (;) - specifies no change in the print cursor.
 
** semi-colon (;) - specifies no change in the print cursor.
 
** comma (,) - specifies that the print cursor is to move to the next 14-column tab-stop. If the print cursor is at column 56 or greater, it is moved to the next line at column 1.
 
** comma (,) - specifies that the print cursor is to move to the next 14-column tab-stop. If the print cursor is at column 56 or greater, it is moved to the next line at column 1.
 
* If {{Parameter|separator}} is not used at the end of the expression list, the print cursor moves to the next line at column 1.
 
* If {{Parameter|separator}} is not used at the end of the expression list, the print cursor moves to the next line at column 1.
* PRINT can also use the + '''concatenation''' operator to combine string values only.
 
 
  
 
* When printing numeric expressions, the following rules are used:
 
* When printing numeric expressions, the following rules are used:

Revision as of 01:14, 5 March 2010

The PRINT statement prints numeric or string expressions to the screen.


Syntax

PRINT [ [expression] [separator] ... ]


Description

  • expression is a numeric or string expression to be printed.
    • SPACE$(n%) or SPC(n%) - specifies that n% space characters will be printed.
    • TAB(column%) - specifies that the print cursor is to move to column number column%. If the print cursor is beyond that column, it is moved to that column on the next line.
    • PRINT can also use the + concatenation operator to combine string values only.
  • separator is used to separate multiple expressions and specifies how the print cursor is to be moved before printing the next expression. It can be one of the following:
    • semi-colon (;) - specifies no change in the print cursor.
    • comma (,) - specifies that the print cursor is to move to the next 14-column tab-stop. If the print cursor is at column 56 or greater, it is moved to the next line at column 1.
  • If separator is not used at the end of the expression list, the print cursor moves to the next line at column 1.
  • When printing numeric expressions, the following rules are used:
    • If the value is positive, the number is prefixed with a space character, otherwise, the number is prefixed with a negative sign (-).
    • If the value is an integer (whole number), no decimal point or fractional part will be printed.
    • If the value is not an integer (whole number) and has zero for a coefficient, no leading zero is printed. For example, -0.123 is printed as "-.123 "
    • If the expression is a numeric literal and is in scientific notation, the number is also printed in scientific notation.
    • The number is suffixed with a space character unless STR$(number) is used.
    • Numerical values MUST be added to a PRINT statement string using commas or semicolons on each side of the value or by using STR$ to convert the value to a string to use string concatenation (+ string addition).


  • VIEW PRINT can set up a viewport area for PRINTs.
  • Whenever PRINT moves the print cursor to a new line, the text viewport is scrolled if necessary. (See VIEW PRINT)
  • Text to be printed can be a STRING variable or a literal value inside of quotation marks.
  • A semicolon at the PRINT string end stops the print cursor immediately for the next PRINT to be appended.
  • Use semicolon ends on bottom 2 rows of the SCREEN mode used or the PRINT will roll the screen up.
  • Commas TAB the print cursor for next data. You can use more than one consecutively.
  • Quotes cannot be inside of the STRING! Use CHR$(34) to place quotation marks inside of a literal string.
  • To better format number and text data placement use PRINT USING.
  • Instead of typing PRINT you can just type a question mark (?). It will change to PRINT when enter is pressed in the IDE.


Examples

Using semicolons, comma tabs or concatenation to insert numbers in a PRINT string:

PRINT "Hello world!" PRINT 123 'demonstrates the positive leading space a$ = "Hello country!" a = 321 PRINT a$, a ' demonstrates comma in statement PRINT a$; a ' demonstrates semicolon in statement PRINT a$ + STR$(a) ' concatenation of string numerical values only ? "Hello city!" ' a ? changes to PRINT after moving cursor from the code line

Hello world! 123 Hello country! 321 Hello country! 321 Hello country! 321 Hello city!

First PRINT prints the text between the quotation marks, then it prints the value 123, notice that there are no quotation marks when printing the value, quotation marks means that it will be treated like a string of text.
a$ is set to "Hello country" and 'a' is set to the value 321, the dollar sign is used when a variable handles text. The contents of a$ is then printed and the "," means that the value of 'a' is printed seperated by a tab and ";" means that there are no separation from the other text.


See also



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page