| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords (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 Get num 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 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 Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
INPUT [ prompt ; ] variable [ , variable ] ...
Data input; always from the terminal (screen/keyboard).
This statement reads one or more values from the "terminal" which is to say the keyboard/screen. These steps are executed:
One interesting exception to step 7 is that if the user presses Return/Enter immediately without typing anything, BASIC does not request more data but assigns a null (if string) or zero (if numeric) to all variable(s). For some unknown reason, the prompt must be a literal string. SYNTAX ERROR is generated if a string variable is specified. A work-around for this problem is to use PRINT prompt ; : INPUT variable... This works pretty well, except ?REDO FROM START (should it occur) will not print the prompt again. Each datum read from the terminal 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 unexpected (non-numeric) characters appear when trying to input into a numeric variable, a ?REDO FROM START is generated. Using a string variable, the (possibly mal-formed) data can be read without error and then tested and converted into a numeric value. Multiple variables read from the terminal must be seperated with a comma (,). If a colon (:) is found, it and everything after will be ignored/lost. This will lead to either ?EXTRA IGNORED or ?? or depending if the colon was encounter while assigning the last variable or not. Leading spaces in the input will be ignored. If a comma, colon, or leading space(s) are needed in an input string, the user must surround the string with double-quotes("). Exception to this rule is the ending double-quote may be omitted if no more variables need to be assigned. There is no way to input a literal double-quote, ASCII Null, or a carriage return. Although Commodore BASIC allows strings to be up to 255 characters in length, the length of all strings combined (in the case of multiple variables) may not be longer than the system's input buffer (this varies by computer model). So if the system has an 80-character input buffer, and two strings are requested, a not-quite-accurate error of STRING TOO LONG would appear if the user typed a string of 40 characters for each variable. This because 40+40 (the two strings) plus 1 for the comma that seperates them, is more than 80. Because of this complex behavior, it is not un-common to see programs that use GET (or INPUT#) instead of INPUT. Or at the very least, limit themselves to one variable per INPUT statement. Along the same lines, several "INPUT replacement" routines have been published in Commodore magazines. INPUT may only be used as a statement in a program. Outside of a program it will generate ILLEGAL DIRECT error. Example:
© H2Obsession, 2014 |