GET

From C64-Wiki
Jump to: navigation, search
Disambiguation The title of this article is ambiguous. GET (Disambiguation).
BASIC keyword
Keyword: GET
Abbreviation: G, Shift+E
Type: Command
Token code: 161/$A1
Handling routine
in BASIC ROM:
43899–43940
$AB7B–ABA4
List of all BASIC keywords


Remark: This article describes the BASIC-Command GET in BASIC V2 at the Commodore 64.

Type: Command
General Programming-Syntax: GET <Variable>[, <Variable>...]


The BASIC command GET reads one or more chars from the keyboard cache into a variable (string, floating point or integer) and can only be used in a BASIC program. When a char from the keyboard cache has been read, there will be space in the cache for one more char. The keyboard cache can store at most 10 chars (by default), further input chars are ignored.

If the specified variable is a string variable then only one character will be read into it.

When a numeric variable has been passed to the command and it gets a non-numeric value, the BASIC error ?SYNTAX ERROR IN line appears. To prevent this BASIC error, it should always be used with a string variable. By using GET directly the BASIC-error "?ILLEGAL DIRECT ERROR" is displayed.

With the command GET, an own routine can be developed for keyboard input and so disadvantages of the BASIC command INPUT can be avoided.

Examples[edit]

10 PRINT "Type max. 20 chars, please: ";:GOSUB 1000
20 PRINT: PRINT "You have written: ";B$
30 END
1000 REM simple GET-INPUT-Routine
1010 A$="": B$="": A=0: REM initialize variables
1020 GET A$: IF A$="" THEN 1020
1030 A=ASC(A$): IF (A<32 OR A>127) AND A<>13 THEN 1020
1040 B$=B$+A$: PRINT A$;: IF LEN(B$)<20 AND A$<>CHR$(13) THEN 1020
1050 RETURN

In this keyboard input routine, all chars of the ASCII code table can be used from 32 (<SPACE>-key) to 127 and 13 (<RETURN>-key). That means all punctuation marks, mathematical symbols, numbers (0-9), and all letters (A-Z in upper and lowercase). Limiting the number of valid chars and keys is important because control chars like <CRSR> can destroy the screen mask. This routine is finished by pushing the <RETURN>-key or by exceeding the 20 chars. Note that in this basic implementation, DEL key is ignored and so the user cannot correct typos. Also, there will be no blinking cursor.

BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT