| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords (divide) (equal) (less) (minus) (more) (multiply) (plus) (power) Abs And Append Asc Atn Auto Backup Bank Begin Bend Bload Boot Box Bsave Bump Catalog Char Chr Circle Close Clr Cmd Collect Collision Color Concat Cont Copy Cos Data Dclear Dclose Dec Def Delete Dim Directory Dispose Dload Do Dopen Draw Ds Ds string Dsave Dverify El Else End Envelope Er Err Exit Exp Fast Fetch Filter Fn For Fre Get Get num Getkey Go Gosub Goto Graphic Gshape Header Help Hex If Input Input num Instr Int Joy Key Left Len Let List Load Locate Log Loop Mid Monitor Movspr New Next Not Off On Open Or Paint Peek Pen Pi Play Pointer Poke Pos Pot Print num Pudef Quit Rclr Rdot Read Record Rem Rename Renumber Restore Resume Return Rgr Right Rlum Rnd Rreg Rspcolor Rsppos Rsprite Run Rwindow Save Scale Scnclr Scratch Sgn Sin Sleep Slow Sound Spc Sprcolor Sprdef Sprite Sprsav Sqr Sshape St Stash Step Stop Str Swap Sys Tab Tan Tempo Then Ti Ti string To Trap Troff Tron Until Using Usr Val Verify Vol Wait While Width Window Xor Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
The keyword includes the # character
PRINT# fileNumber [ , [ { , | ; } ] ... [ { expression | TAB(n) | SPC(n) } [ { , | ; } [ { expression | TAB(n) | SPC(n) } ] ] ... ] ]
Print an expression(s) to the device corresponding to fileNumber.
PRINT# is pretty versatile; it will accept any number or type of expressions; the only requirement is the fileNumber which must correspond with an OPEN'd file. The number of expressions is limited only by the length of a BASIC program line; you may have zero expressions. Each expression may be of numeric or string type; each may be a literal value (e.g., the number 7 or the string "hello"), a variable, a simple function (such as ABS(X) or STR$(X)), or a "BASIC forumula" (which includes actual mathematical forumulas, such as 2*X+1, and so-called "string formulas" like A$+CHR$(X)). The PRINT# keyword has its own token, completely different from PRINT. This means you can't abbreviate PRINT# with ?# and also means you can't have any space between PRINT and #. You may have space(s) between PRINT# and the fileNumber. Besides printing an expression, you may also "print" spaces (code 32) with the SPC(n) preposition or nothing with the TAB(n) preposition. If the value of n is not legal (see above) then an ILLEGAL QUANTITY ERROR is generated. The SPC preposition will add n spaces after the last expression (if any). The TAB preposition does nothing because BASIC has no idea of the "current column" of the output device. By opening a "file" to device 3, PRINT# sends its output to the active display screen (the C128 has two display screens and one is active; all other CBMs only have one screen which is always active). This is rarely done because PRINT (without #) sends to the screen by default. Anyway, when the output is going to the screen, many secret variables can be updated by "printing" control codes (see the PETSCII table). The optional comma (,) will seperate surrounding expressions by a "virtual tab stop" which occurs once every 10 columns (SCREEN DISPLAY ONLY). Note most CBM machines do not have Tab stops on the display screen; the C128 does have Tab stops (which may be defined anywhere) but they are ignored by PRINT# (it always uses the 10-column rule). If a PRINT# statement ends with a comma, the output is set to the next "virtual tab stop" and no "new line" (see below) is sent to the output device. The optional semicolon (;) will not separate surrounding expressions; the will "run together". This is obvious with strings (see examples), but most numerical expressions will appear separated because PRINT# will include a trailing space behind each number, and positive numbers (which are very common) will have a leading space. (See STR$ for details about how BASIC formats numeric values.) I hate to complicate things, but (contrary to the Syntax shown above) BASIC will often allow you to omit a semicolon with the same effect as including one between two expressions; this is possible when there is no ambiguity between two expressions. To be nagative, this makes for hard-to-read (sloppy) code, but on the positive side this feature allows programs to be more compact (thus less memory use and faster execution). Anyway, if a PRINT# statement ends with a semicolon, the output position is not changed; that is, no "new line" (see below) is sent to the output device. If the statement does not end with one of the two optional punctuation marks (a comma or semicolon), then PRINT# will end by sending a "new line" to the output device. By default, this is a terminating carriage return (code 13). Under some cases (see OPEN) it may also send a terminating line feed (code 10). Some versions of BASIC (those > 2) allow a USING clause which allows for further customization of how each expression is generated. If fileNumber was not previously OPEN'd, then a FILE NOT OPEN ERROR is generated; otherwise, PRINT# does not (itself) generate an error, however any invalid expression will generate an error (for example SYNTAX ERROR, or TYPE MISMATCH ERROR); this also applies to the n parameter of the SPC and TAB prepositions. Using a PRINT# fileNumber [ expr...] statement will send expr... (if any) to the fileNumber and then re-direct BASIC to use the default (active display screen) output device. This is highly recommended prior to CLOSE. The reason is that some devices will buffer data until a carriage return (or maybe line feed) is detected; the PRINT# statement (without a trailing comma or semicolon) will send this code(s) and thus "flush" any buffered data prior to CLOSE. Examples:
© H2Obsession, 2014 |