WriteLine Method

Writes a specified string and newline character to a TextStream file.

Syntax

object.WriteLine([string])

Arguments

  • Object: Required. Always the name of a TextStream object.

  • String: Required. The text you want to write to the file.

Remarks

The following example illustrates use of the WriteLine method:

Example 1:

Function WriteLineToFile
    Const ForWriting = 2
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile("C:\testfile.txt", ForWriting, True)
    f.WriteLine "Hello World!"
    f.Close
End Function

Example 2:

Function AppendLinesToFile
    Const ForAppending = 8
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile("C:\testfile.txt", ForAppending, True)
    f.WriteLine "First line."
    f.WriteLine "Second line."
    f.WriteLine "Third line."
    f.Close
End Function