ReadLine Method
Reads an entire line (up to, but not including, the newline character) from a
TextStream
file and returns the resulting string.
Syntax
object.ReadLine( )
Arguments
Object: Required. Always the name of a TextStream
object.
Remarks
The following example illustrates the use of the ReadLine
method:
Example 1:
Function ReadFirstLine(filepath)
Const ForReading = 1
Dim fso, theFile, firstLine
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filepath, ForReading)
firstLine = theFile.ReadLine
theFile.Close
ReadFirstLine = firstLine
End Function
' Usage
Dim firstLineContent
firstLineContent = ReadFirstLine("C:\Path\To\Your\File.txt")
Example 2:
Function ReadFileLineByLine(filepath)
Const ForReading = 1
Dim fso, theFile, line
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filepath, ForReading)
Do While Not theFile.AtEndOfStream
line = theFile.ReadLine
Loop
theFile.Close
End Function
' Usage
ReadFileLineByLine "C:\Path\To\Your\File.txt"