Home > CBM > BASIC > Keywords > Get num | ||||||||||||||||||||||||||||||||||||||||||||
GET # file_number , variable [ , variable ] ...
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 #). Example:
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.
© H2Obsession, 2014 |