LINE INPUT: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "The LINE INPUT statement requests a STRING keyboard entry from a program user. {{PageSyntax}} : LINE INPUT [;] "[text prompt or question]"{,|;} {{Parameter|stringVariable$}} : LINE INPUT ; {{Parameter|stringVariable$}} {{Parameters}} * A semicolon immediately after LINE INPUT stops the cursor after the entry and prevents screen roll on the lowest two screen rows. * ''text prompt or question'' is optional, but quotes are necessary unless just a sem...") |
No edit summary |
||
Line 15: | Line 15: | ||
{{PageDescription}} | {{PageDescription}} | ||
* Cannot use numerical [[type]] variables or [[comma]] separated variable lists for multiple entries. | * Cannot use numerical [[type]] variables or [[comma]] separated variable lists for multiple entries. | ||
* Allows [[comma]]s and [[quotation mark]]s in the user input, unlike [[INPUT]] where commas denote extra input values and quotes delimit strings. | * Allows [[comma]]s and [[quotation mark]]s in the user input, unlike [[INPUT]] where commas denote extra input values and quotes delimit strings. | ||
* The statement halts the program until an entry is made. Pressing Enter ends the entry and code execution resumes. | * The statement halts the program 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. | * 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), [[&H]] (hexadecimal) or [[&B]] (binary) prefixed entries into numerical values. | * Use [[VAL]] to convert string numbers and [[&O]] (octal), [[&H]] (hexadecimal) or [[&B]] (binary) prefixed entries into numerical values. | ||
* Use [[_DEST]] [[_CONSOLE]] before LINE INPUT statements to receive input from a [[$CONSOLE|console]] window. | * Use [[_DEST]] [[_CONSOLE]] before LINE INPUT statements to receive input from a [[$CONSOLE|console]] window. | ||
* '''Note: QB64''' will not remove CHR$(0) from the end of LINE INPUT string return values like QBasic did. | * '''Note: QB64''' will not remove CHR$(0) from the end of LINE INPUT string return values like QBasic did. | ||
Line 24: | Line 24: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' Preventing screen roll after an input entry on the bottom 2 screen rows. | ''Example:'' Preventing screen roll after an input entry on the bottom 2 screen rows. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} 12 | {{Cl|SCREEN}} 12 | ||
Line 35: | Line 35: | ||
{{Cl|COLOR}} 14' change foreground color to yellow | {{Cl|COLOR}} 14' change foreground color to yellow | ||
{{Cl|LOCATE}} 29, 2: {{Cl|PRINT}} "Searching..."; 'print message | {{Cl|LOCATE}} 29, 2: {{Cl|PRINT}} "Searching..."; 'print message | ||
{{Cl|SLEEP}} | {{Cl|SLEEP}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}}{{text|Enter a name to search for...|#FFFF00}} █ | {{OutputStart}}{{text|Enter a name to search for...|#FFFF00}} █ | ||
Line 42: | Line 42: | ||
''See also:'' | ''See also:'' | ||
* [[INPUT (file mode)]], [[INPUT (file statement)|INPUT #]], [[LINE INPUT (file statement)|LINE INPUT #]] | * [[INPUT (file mode)]], [[INPUT (file statement)|INPUT #]], [[LINE INPUT (file statement)|LINE INPUT #]] | ||
* [[INPUT]], [[INPUT$]] {{text|(keyboard input)}} | * [[INPUT]], [[INPUT$]] {{text|(keyboard input)}} | ||
* [[COLOR]], [[LOCATE]] | * [[COLOR]], [[LOCATE]] | ||
* [[INKEY$]] | * [[INKEY$]] | ||
* [[_KEYHIT]], [[_KEYDOWN]] | * [[_KEYHIT]], [[_KEYDOWN]] |
Revision as of 01:57, 23 January 2023
The LINE INPUT statement requests a STRING keyboard entry from a program user.
Syntax
- LINE INPUT [;] "[text prompt or question]"{,|;} stringVariable$
- LINE INPUT ; stringVariable$
- A semicolon immediately after LINE INPUT stops the cursor after the entry and prevents screen roll on the lowest two screen rows.
- text prompt or question is optional, but quotes are necessary unless just a semicolon is used before the stringVariable$.
- Requires only one string variable to hold the entire text entry.
Description
- 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 halts the program 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), &H (hexadecimal) or &B (binary) prefixed entries into numerical values.
- Use _DEST _CONSOLE before LINE INPUT statements to receive input from a console window.
- Note: QB64 will not remove CHR$(0) from the end of LINE INPUT string return values like QBasic did.
Examples
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:
- INPUT (file mode), INPUT #, LINE INPUT #
- INPUT, INPUT$ (keyboard input)
- COLOR, LOCATE
- INKEY$
- _KEYHIT, _KEYDOWN