LINE INPUT statement(from file)

Purpose: Reads a line of text data from a file.


 Syntax 1:

 LINE INPUT hFile, Buffer$

 Parameters:

  • hFile Name of handle to file from which line of text is read. File must be opened using
    
     OPEN FileName$ FOR INPUT AS hFile
    
    
    syntax.
  • Buffer$ String to receive line of text.

Example: LINE INPUT from file


 DIM a$
 DIM z%

 a$ = "Test"

 OPEN a$ FOR OUTPUT AS fp1
 ? "Creating test file ..."
 FOR z% = 1 TO 1000
  FPRINT fp1, "This is line no.", STR$(z%)
 NEXT
 CLOSE fp1

 OPEN a$ FOR INPUT AS fp1
 WHILE NOT EOF(fp1)
  LINE INPUT fp1, a$
  ? a$
 WEND
 CLOSE fp1

 CLS

 ? "Removing Test file"

 KILL "test"

LINE INPUT statement(from keyboard)

Purpose: Reads a line of text data from the keyboard. Similar to the INPUT statement, LINE INPUT allows text including commas and quotation marks to be input from the keyboard. See also the INPUT statement.


 Syntax 2:

 LINE INPUT "Prompt", Buffer$

 Syntax 3:

 LINE INPUT Prompt$, Buffer$

 Parameters:

  • Prompt is NOT optional but will allow a string variable, Prompt$, or a string literal, "Prompt", for the user prompt. If you don't want a prompt, do this:
    
     LINE INPUT "", Buffer$
    
    
  • Buffer$ String to receive the line input text.

Remarks:

LINE INPUT allows you to collect characters typed on the keyboard, including commas, without the special need to use quotation marks. This is mostly compatible with PowerBasic and Qbasic except in BCX, the prompt is not optional.

Example 1: Simple string variables


 DIM a$
 LINE INPUT "First Name, Last Name? ", a$
 PRINT a$

Example 2: String Array variables


 DIM b$[10,10]
 LINE INPUT "First Name, Last Name? ", b$[5,5]
 PRINT b$[5,5]