Wiki source for KeyPgInput


Show raw source

{{fbdoc item="title" value="INPUT"}}----
Reads a list of values from the keyboard

{{fbdoc item="syntax"}}##
**Input** [;] ["//prompt//" ,|; ] //variable_list//
##
{{fbdoc item="param"}}
##//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_list//##
a list of comma-separated variables used to hold the values read from the user.

{{fbdoc item="desc"}}
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 being split up.
For inputting to a single string without delimiting, ##[[KeyPgLineinput|Line Input]]## should be used instead.

The ##//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 ##**Input**## is similar to the optional trailing semicolon in a ##[[KeyPgPrint|Print]]## statement: the cursor will remain on the same line after all of the characters have been echoed, otherwise, the cursor will move to the beginning of the next 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 variables to the empty string (##"####"##)).

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

##**Input**## has a limited edit capacity: it allows to erase characters using the backspace key. If a better user interface is needed, a custom input routine should be used.

{{fbdoc item="ex"}}

**Example #1**
{{fbdoc item="filename" value="examples/manual/console/input.bas"}}%%(freebasic)
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**
{{fbdoc item="filename" value="examples/manual/console/input2.bas"}}%%(freebasic)
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"
%%

{{fbdoc item="diff"}}
- 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 when inputting a number from the console.

{{fbdoc item="see"}}
- ##[[KeyPgInputPp|Input #]]##
- ##[[KeyPgInputnum|Input()]]##
- ##[[KeyPgLineinput|Line Input]]##

{{fbdoc item="back" value="CatPgInput|User Input"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode