LINE INPUT - QB64 Wiki

LINE INPUT

From QB64 Wiki

Jump to: navigation, search

The LINE INPUT statement requests a STRING keyboard entry from a program user.


Syntax:

LINE INPUT [;] "[text prompt or question]"{,|;} string_variable$
LINE INPUT ; string_variable$


Parameters:

  • semicolon after LINE INPUT stops the cursor after the entry and prevents screen roll on lowest two screen rows.
  • text statement or question is optional, but quotes are necessary unless just a semicolon is used before the variable.
  • comma separator for a statement or semicolon for a question mark following the text.
  • No text with a semicolon displays a question mark with a space and keeps the cursor after the entry.
  • Requires ONE string variable to hold the entire text entry.


Usage:

  • Cannot use numerical type variables or comma separated variable lists for multiple entries!
  • Allows commas and quotation marks in the user input, unlike INPUT where commas denote extra input values and quotes delimit strings.
  • The statement stops the procedure until an entry is made. Pressing Enter ends the entry and code execution resumes.
  • LINE INPUT does not trim off leading or trailing spaces in the string entry like INPUT string returns.
  • Use VAL to convert string numbers and &O(octal) or &H(hexadecimal) prefixed entries into numerical values.
  • Use _DEST _CONSOLE before LINE INPUT statements to be used in a console window.
  • Note: QB64 will NOT remove CHR$(0) from the end of LINE INPUT string return values like Qbasic did.


Example: Preventing screen roll after an input entry on the bottom 2 screen rows.

SCREEN 12 COLOR 14: LOCATE 29, 2 ' place dursor at beginning of prompt liine PRINT "Enter a name to search for... "; 'print prompt on screen COLOR 15: LINE INPUT ; "", name$ ' get search name from user LOCATE 29, 2: PRINT SPC(78); ' erase previous prompt n$ = UCASE$(name$) ' convert search name to upper case COLOR 14' change foreground color to yellow LOCATE 29, 2: PRINT "Searching..."; 'print message SLEEP

Enter a name to search for...

Explanation: The red semicolon after LINE INPUT acts like a semicolon after a PRINT, which keeps the print cursor on the same row.


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Views
Personal tools