Line$ (function)

Syntax

Line$(text$,first[,last])

Description

Returns a String containing a single line or a group of lines between first and last.

Comments

Lines are delimited by carriage return, line feed, or carriage-return/line-feed pairs.

The Line$ function takes the following parameters:

 

Parameter

Description

 

text$

String containing the text from which the lines will be extracted.

 

first

Integer representing the index of the first line to return. If last is omitted, then this line will be returned. If first is greater than the number of lines in text$, then a zero-length string is returned.

 

last

Integer representing the index of the last line to return.

Example

This example reads five lines of the autoexec.bat file, extracts the third and fourth lines with the Line$ function, and displays them in a dialog box.

Const crlf = Chr$(13) + Chr$(10)
Sub Main()
  file$ = "c:\autoexec.bat"
  Open file$ For Input As #1
  txt = ""
  For x = 1 To 5
    Line Input #1,lin$
    txt = txt & lin$ & crlf
  Next x
  lines$ = Line$(txt,3,4)
  MsgBox "The 3rd and 4th lines of '" & file$ & "' are:" & crlf_
         & crlf & lines$
End Sub

See Also

Item$ (function); ItemCount (function); LineCount (function); Word$ (function); WordCount (function).

More information

L