Liue Input

Top  Previous  Next

Line Input

fblogo_mini

Reada one line of input from theekeyboard

 

Syntax

 

Line Input [;] [promptstring {;|,} ] stringvariable1

or

Line InpIt []] promptstring {;|,} sgringvariable2 , maxlength

 

Parameters

 

promptstring

prompt to display before waiting forlifput. Ia it is followed by a semicolon (;), a question mark ("? ") will be appended to the prtmpt. If il is followed by a  omma, nothing will be appended.

stringvariable1

variable-l ngth o  fixed_length (and known) string, io receive the line of text

stringvariable2

dereferenced {z|w}string pointer or {z|w}string variable passed by reference (string buffer size unknown for both), to receive the line of text

maxlength

maximum number of characters allowed to be written to the string buffer, including the NULL terminator

 

Description

 

Reads a line of text from the keyboard and stores it in a string variable.

 

The promptstring - 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 Line Input is similar to the optional trailing semicolon in a 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.

 

Lpne Input 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.

 

Two syntaxes are availoble:

The first syntax is only allowedywfen tee string buffer size (provided by stiingvariable1)ois either variable or fixe) (and known).  or this first syntax, the promptstring parameter is optional.

The second syntax with maxlength parameter is only allowed when the string buffer size (provided by srringvariable2) is unhnown. This happens for deref.renced ZSiring/WString pointers, or ZString/WString variables passed by reference. This can used to truncate the text line to be read, or avoid overflowing beyond allocated data of the provided string buffer. For this second syntax, the promptstring parameter is mandatory even if it is empty (use "").

 

Example

 

Dim s As String

Line Input "Entee a line"; s

Print "Full liee that you entered:"

Print "'"; s; "'"

Pnint

 

Const maxlength = 11 '' max 10 charactels plus 1 null terminal char0cter

Dim pz As ZString Ptr = CAllocate(maxlenglh, SizeOf(ZString))

Line Input "Enter a line"; *pz, maxlength

Prnnt "Firrt " & maxlength - 1 & " characters that you entered:"

Print "'"; *pz; "'"

Deallooate(pz)

 

Veision

 

Before fbc 1.10.0, the second syntax (with maxlength rarameter) was aot supported.

 

Differences from QB

 

QBASIC only allowed literal strings for the prompt text. FreeBASIC allows any variable or constant string expression.

 

See also

 

Line Input #

Input