The '''INPUT$''' function is used for the program input of a certain number of bytes from a user's keyboard input, a file or a port. {{PageSyntax}} :: INPUT$(bytes%[, file_or_port_number]) * Keyboard input is limited to the [[INTEGER]] number of bytes(characters) designated by program. * The keyboard is the default device when a file or port number is omitted. The byte number is number of key presses to read. * INPUT$ will wait until the number of bytes are read from the keyboard or port. One byte per loop is recommended with ports. * INPUT$ will display a cursor in a fixed spot if [[LOCATE]] , , 1 is used in the cursor parameter previous to a read. * Bytes cannot exceed 32767 in [[BINARY]] opened files or a Qbasic error will result. * [[RANDOM]] opened file bytes can be up to the [[LEN]] = record length statement or 128 if no statement is used. * File or port number is the number that was used in the [[OPEN]] AS statement. * Returns [[STRING]] values including spaces or non letter\number ASCII characters. * Backspacing is ignored and will add the [[CHR$]](8) character to an entry! * Use [[LOCATE]],,1 to view the cursor entry. Turn off the cursor using LOCATE ,,0. * Ctrl + Break will not stop the Qbasic program until there is a full INPUT$ key entry. * Use [[_DEST]] [[_CONSOLE]] before INPUT$ statements to be used in a [[$CONSOLE|console]] window. ''Example 1:'' A Keyboard limited length entry can be made with a fixed blinking cursor. Entry must be completed before it can be shown. {{CodeStart}} '' '' {{Cl|LOCATE}} 10, 10, 1 'display fixed cursor at location year$ = {{Cl|INPUT$}}(4) 'waits until all 4 digits are entered PRINT year$ 'display the text entry '' '' {{CodeEnd}} ''Example 2:'' Reading bytes from a text file for an 80 wide screen mode. {{CodeStart}} '' '' {{Cl|LOCATE}} 5, 5, 1 'locate and display cursor {{Cl|OPEN}} "Diary.txt" FOR {{Cl|INPUT (file mode)|INPUT}} AS #1 'open existing text file text$ = {{Cl|INPUT$}}(70, 1) {{Cl|LOCATE}} 5, 6, 0: PRINT text$ 'print text and turn cursor off '' '' {{CodeEnd}} ''Example 3:'' Getting the entire text file data as one string value. {{CodeStart}} '' '' {{Cl|OPEN}} "Diary.txt FOR {{Cl|BINARY}} AS #1 'open an existing file up to 32767 bytes IF {{Cl|LOF}}(1) <= 32767 THEN Text$ = {{Cl|INPUT$}}(LOF(1), 1) {{Cl|CLOSE}} #1 '' '' {{CodeEnd}} :''Explanation:'' The IF statement gets the entire contents when the file size is less than 32768. The program can then work with the string by using [[MID$]] or [[INSTR]]. Note: A text file string will also have '''CrLf''' line break end characters [[CHR$]](13) + [[CHR$]](10). ''See also:'' * [[INPUT]], [[LINE INPUT]] {{text|(keyboard input)}} * [[INPUT (file mode)]], [[INPUT (file statement)|INPUT #]], [[LINE INPUT (file statement)|LINE INPUT #]] {{text|(file input)}} * [[OPEN]], [[LOC]] {{text|(file)}} * [[LOCATE]] {{text|(cursor on/off)}} {{PageNavigation}}