问题在于十四号。否则就是语法错误,(800A03EA)我对VBScript很新。
Dim StrThing, fso, f
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
If f.FileExists("Desktop\testfile") then
StrThing=InputBox("Type your name in")
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForWriting, True)
f.WriteLine "Hello world!"
f.WriteLine "Hello, " & StrThing
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForReading)
WriteLineToFile = f.ReadAll
StrThing=MsgBox("Hello, " & StrThing)
StrThing=MsgBox("Goodbye, " & StrThing)
End if
Else
x=MsgBox("Hello")
f.createTextFile
StrThing=InputBox("Type your name in")
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForWriting, True)
f.WriteLine "Hello world!"
f.WriteLine "Hello, " & StrThing
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForReading)
WriteLineToFile = f.ReadAll
StrThing=MsgBox("Hello, " & StrThing)
StrThing=MsgBox("Goodbye, " & StrThing)
End if
答案 0 :(得分:0)
此处需要进行两项更改。
else
后if
语句开始
f.FileExists
←没有为f
定义对象。Dim StrThing, fso, f
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = CreateObject("Scripting.FileSystemObject")
If f.FileExists("Desktop\testfile.txt") then
StrThing=InputBox("Type your name in")
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForWriting, True)
f.WriteLine "Hello world!"
f.WriteLine "Hello, " & StrThing
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForReading)
WriteLineToFile = f.ReadAll
StrThing=MsgBox("Hello, " & StrThing)
StrThing=MsgBox("Goodbye, " & StrThing)
Else
x=MsgBox("Hello")
f.createTextFile
StrThing=InputBox("Type your name in")
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForWriting, True)
f.WriteLine "Hello world!"
f.WriteLine "Hello, " & StrThing
Set f = fso.OpenTextFile("Desktop\testfile.txt", ForReading)
WriteLineToFile = f.ReadAll
StrThing=MsgBox("Hello, " & StrThing)
StrThing=MsgBox("Goodbye, " & StrThing)
End if