Home > CBM > BASIC > Keywords > Cmd | |||||||||||||||||||||||||||||||||||||||||||||||||
Optionally, CMD allows printing an expression; it also allows you to "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 the system has no idea what the "current column" of the output device may be. The fileNumber must be the number used by a previous OPEN command; otherwise a FILE NOT OPEN ERROR is generated. In some cases, OPEN will not generate an error, even though it "failed" (for example, device not present); in these cases, CMD will also not generate an error. If the target device happens to be the display screen (quite rare) then many secret variables may be updated by printing control codes (see the PETSCII table). If the fileNumber refers to the keyboard or to a cassette file opened for reading, then NOT OUT FILE ERROR will be generated. No error will be displayed if a "disk file" was opened for reading. After CMD has successfully executed, further normal BASIC text output will be sent to the specified fileNumber. This typically includes the output of PRINT and LIST, but also include "informational" messages such as "LOADING" and "READY." If an error occurs (or after a PRINT# fileNumber statement is executed), then BASIC will revert to the defalut (active display screen) output. CMD is often used to redirect screen output to a printer; for example, to generate a "hard copy" of a program listing. The optional comma (,) will seperate surrounding expressions by a "virtual tab stop" which occurs once every 10 columns, IF THE OUTPUT DEVICE IS THE SCREEN; otherwise the results are undefined (device-specific)... The optional semicolon (;) will not separate surrounding expressions; they will "run together". This is obvious with strings (see examples), but most numerical expressions will appear separated because CMD 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 CMD 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. Besides the possible errors mentioned above, 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 and thus "flush" any buffered data prior to CLOSE. Examples:
© H2Obsession, 2014 |