Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎


Keyword Abbreviation Token (hex) Version(s) Classification
GET # G{Shift+E}# A1 23 1.0 to 7.0 Statement

GET # file_number variable [ , variable ] ...
Parameters Type Legal Value(s) Default Value Note(s)
file_number Integer 0~255   Must be the number of an open "file"
variable String or numeric any except reserved variable Type must be valid for the data that comes in
Data input; typically from an external device.

This statement reads one or more characters from the "file" associated with file_number and stores it/them in the specified variable(s).  Each datum read from the file must be compatible with each variable's type.  So a string variable must be specified if text is to be read.  A numeric variable (integer or float) is sometimes used to read numeric values, but often a string variable will be used in these cases too.  This is because if a non-numeric character appears when trying to input into a numeric variable, a FILE DATA ERROR is generated.  By using a string variable, any character will be accepted.
If the file_number was never opened (or was opened but then closed), GET# will generate FILE NOT OPEN ERROR.
If the "file" does not have data available, GET# will assign zero to a numeric variable or an zero-length string to a string variable.
A "bug" in all versions of CBM BASIC is that a character with code zero (a.k.a. CHR$(0), a.k.a. "null") is stored into a string variable as a zero-length string instead of a 1-character string with code zero.  This is especially important for BASIC versions before 3.5 because they will generate an error with the ASC function if the string is empty (zero length).
GET# may only be used as a statement in a program.  Outside of a program it will generate ILLEGAL DIRECT error. If flie_Number is omitted or no variables are specified, GET# will generate SYNTAX ERROR.
Trivia: the GET# keyword is actually the token GET followed by the ASCII code for "#" which means that (unlike most statments) you may include a space in the "keyword" (but only between GET and #). 
10 OPEN 72,0 : REM open the keyboard as file #70
20 GET# 72, K$ : IF K$ = "" THEN 20
40 CLOSE 72

H           user typed an H 

The above example is pretty silly because you don't need to use OPEN/CLOSE to GET from the keyboard; however it is the only example I can think of that will work on all CBMs.
  Compare With  
  Contrast With  
  See Also  

© H2Obsession, 2014