Home > CBM > BASIC > Keywords > Get num
180 Subpages: (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, 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, 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

KeywordAbbreviationToken (hex)Version(s)Classification
GET #G{Shift+E}#A1 231.0 to 7.0Statement

 
Syntax 
GET # file_number variable [ , variable ] ...
 
ParametersTypeLegal Value(s)Default ValueNote(s)
file_numberInteger0~255 Must be the number of an open "file"
variableString or numericany except reserved variableType must be valid for the data that comes in
 
 
Purpose 
Data input; typically from an external device.

 
 
Remarks 
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:
NEW

READY.
10 OPEN 72,0 : REM open the keyboard as file #72
20 GET# 72, K$ : IF K$ = "" THEN 20
30 PRINT K$
40 CLOSE 72
RUN
H           user typed an H 

READY.

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