filesystemobject組件的用法樣本

來源:互聯網
上載者:User

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' CreateLyrics

' 目的:

' 在檔案夾中建立兩個文字檔。

' 示範下面的內容

' - 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 ") ' 請注意,該語句不添加換行到檔案中。

TextStream.WriteLine("(by Ringo Starr)")

TextStream.WriteBlankLines(1)

TextStream.WriteLine("I'd like to be under the sea in an octopus' garden in the shade,")

TextStream.WriteLine("He'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 The 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

' 目的:

' 顯示 lyrics 檔案的內容。

' 示範下面的內容

' - FileSystemObject.OpenTextFile

' - FileSystemObject.GetFile

' - TextStream.ReadAll

' - TextStream.Close

' - File.OpenAsTextStream

' - TextStream.AtEndOfStream

' - TextStream.ReadLine

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function GetLyrics(FSO)

Dim TextStream

Dim S

Dim File

' 有多種方法可用來開啟一個文字檔,和多種方法來從檔案讀取資料。

' 這兒用了兩種方法來開啟檔案和讀取檔案:

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 While Not TextStream.AtEndOfStream

S = S & TextStream.ReadLine & NewLine

Loop

TextStream.Close

GetLyrics = S

End Function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.