Skip to content

INPUT

Source: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgInput Last revised: 2020-11-12

Reads values from the keyboard.

Syntax

Input [;] ["prompt" ,|; ] variable_list

Parameters

  • prompt — An optional string literal written to the screen. If followed by ;, a question mark "? " is appended. If followed by ,, nothing is appended.
  • variable_list — A list of comma-separated variables to hold the values read from the user.

Description

Input reads a list of values from the keyboard until the first carriage return. Numerical values are converted from string representation. Characters are echoed to the screen as typed.

Delimiters: If there is more than one value in the input list:

  • Strings are delimited by commas.
  • Numbers are delimited by commas and whitespace.
  • Surrounding whitespace is trimmed from string values.
  • A string with a comma must be wrapped in quotes to prevent splitting.

For inputting to a single string without delimiting, use Line Input instead.

Leading semicolon (;): The cursor will remain on the same line after input, similar to a trailing semicolon in Print.

If more values are read than variables: Extra values are ignored.

If fewer values are read: Remaining variables are initialized (numeric to 0, strings to "").

Edit capacity: Left/right cursor keys to navigate, erase or insert characters.

Examples

Example 1:

vb
Dim user_name As String, user_age As Integer
Input "Enter your name and age, separated by a comma: ", user_name, user_age
Print "Your name is " & user_name & ", and you are " & user_age & " years old."

Example 2:

vb
Dim As Double a, b
Dim As String yn
Do
    Input   "Please enter a number: ", a
    Input ; "And another: ", b
    Print , "Thank you"
    Sleep 500
    Print
    Print "The total is "; a + b
    Print
    Do
        Input "Would you like to enter some more numbers"; yn
        yn = LCase(yn)
    Loop Until yn = "y" Or yn = "n"
Loop While LCase(yn) = "y"

Differences from QB

  • In QBASIC, if the user inputs wrong values, it issues "Redo from start" and does not continue until valid input is received.
  • QB does not treat space as a delimiter when inputting a number.

See Also

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft