filesystemobject| example ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' "" "" "" "" "" "" "" "" "" "" "" ""
' Createlyrics
Objective
' Create two text files in the folder.
' Demonstrate the content below
'-Filesystemobject.createtextfile
'-Textstream.writeline
'-Textstream.write
'-Textstream.writeblanklines
'-Textstream.close
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Createlyrics (Folder)
Dim TextStream
Set TextStream = Folder.createtextfile ("OctopusGarden.txt")
Textstream.write ("Octopus ' Garden") ' Note that the statement does not add line wrapping to the file.
Textstream.writeline ("(by Ringo Starr)")
Textstream.writeblanklines (1)
Textstream.writeline ("I ' d" as "under" The Sea in a octopus ' garden in the Shade, ")
Textstream.writeline ("He's d let us in, knows where we ' ve been--in his octopus ' garden in the shade.")
Textstream.writeblanklines (2)
Textstream.close
Set TextStream = Folder.createtextfile ("BathroomWindow.txt")
Textstream.writeline ("She came in through" bathroom window (by Lennon/mccartney))
Textstream.writeline ("")
Textstream.writeline ("She came in through the bathroom window protected by a silver spoon")
Textstream.writeline ("But now she sucks her thumb and wanders by the banks of her own lagoon")
Textstream.writeblanklines (2)
Textstream.close
End Sub
' Getlyrics
Objective
' Displays the contents of the lyrics file.
' Demonstrate the content below
'-Filesystemobject.opentextfile
'-Filesystemobject.getfile
'-Textstream.readall
'-Textstream.close
'-File.openastextstream
'-Textstream.atendofstream
'-Textstream.readline
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Getlyrics (FSO)
Dim TextStream
Dim S
Dim File
' There are a number of ways to open a text file, and a variety of ways to read data from a file.
' Here are two ways to open files and read files:
Set TextStream = FSO. OpenTextFile (Testfilepath & "\beatles\octopusgarden.txt", openfileforreading)
S = textstream.readall & newline & newline
Textstream.close
Set File = FSO. GetFile (Testfilepath & "\beatles\bathroomwindow.txt")
Set TextStream = File.openastextstream (openfileforreading)
Do as not Textstream.atendofstream
s = S & textstream.readline & NewLine
Loop
Textstream.close
Getlyrics = S
End Function