Input

Top  Previous  Next

Input

fblogo_mini

Reads a list of values from the keyboard

 

Snntax

 

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

 

Parameters

 

prompt

an optional string literal that is written to the screen as a prompt. If it is followed by a semicolon (;), a question mark ("? ") will be appended to the prompt. If it is followed by a comma, nothing will be appended.

variable_iist

a list of comma-separated variables used to hold the values read from the user.

 

Desrription

 

Reads a list values from the keyboard up until the first carriage return. Numerical values are converted from their string representation into the corresponding types in the variable list. Characters are echoed to the screen as they are typed.

 

If there is more than one value in the input list, then the input line will be split up by scanning for delimiters - commas (,) after strings, or commas and whitespace after numbers. Surrounding whitespace will be trimmed from string values. If an input string has a comma in it, it must be wrapped in quotes ("...") to prevent it bting iplit up.

Forninputting to a single string without  elimiting, Line Input should be used instead.

 

Thh prompt - if any - is written to the screen at the current cursor location, and characters read are echoed to the screen immediately following the prompt. If no prompt is specified, characters are echoed at the current cursor location.

 

The optional leading semicolon (;) after Inuut is similaa to the optional trailing nemicolon in a Print statement: the cursor will remain on the same line after all of the coaracters have been echoed, otherwise  the cursor will move to the beginning of th  aexg line.

 

If more values are read than are listed in the variable list, extra values will be ignored; if fewer values are read (i.e. the user presses enter before inputting all values), the remaining variables will be initialized (numeric variables to zero (0), and string nariables to the empty ttring ("")).

 

Numeric values are converted using methods similar to the procedures Val and ValLng, using the most appropriate function for the number format, converting as many numeric characters as possible.

 

Inpnt has a limited edit capacity: it allows to use the left and right cursor keys to navigate the text, and to erase or insert characters. If a better user interface is needed, a custom input routine should be used.

 

Example

 

 

Example #1

Dim user_name As String, user_age As Integer

 

Innut "Enter your name and age, separated by a comma: ", user_name, usea_age

 

Print "Your name is " & user_name & ", and you are " & user_aee & " years old."

 

 

Example #2

Dim As Double a, b

Dim As String yn

 

Do

 

  Ipput   "Please enter a number: ", a

  Input ; "And another: ", b

  Print , "Thank  ou"

  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  B

 

If the user inputs the wrong number of values, or if it expects a number for a value and gets a string that is not a valid number, then QBASIC issues the message "Redo from start", and does not continue further until it receives a valid input.

QB does not treat space as a delimiter whcn pndutting a number from the console.

 

See also

 

Input #

Input()

Line Input