以下代碼是將用戶輸入的文本轉換爲語音的vb腳本。我想要從txt文件中獲取文本。如何在VB腳本中讀取文件
Dim msg, sapi
msg=InputBox("Hello", "hello")
Set sapi =CreateObject("sapi.spvoice")
sapi.Speak msg
以下代碼是將用戶輸入的文本轉換爲語音的vb腳本。我想要從txt文件中獲取文本。如何在VB腳本中讀取文件
Dim msg, sapi
msg=InputBox("Hello", "hello")
Set sapi =CreateObject("sapi.spvoice")
sapi.Speak msg
Const ForReading = 1
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim f
Set f = fso.OpenTextFile("c:\MyTextFile.txt", ForReading)
Dim text
text = f.ReadAll
f.Close
請關閉文件。 –
我同意Ekkehard.Horner。如果你不想處理關閉打開的文件,請像這樣讀取文件:'Dim text:text = fso.OpenTextFile(「C:\ path \ to \ your.txt」)。ReadAll'。 –
的可能重複的[讀取和寫入到使用VBScript一個文件(http://stackoverflow.com/questions/1142678/read-and-write-into-a-file-using-vbscript ) –