The problem is on line fourteen. Else is somehow a syntax error, (800A03EA) I'm very new to 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
Two changes required here.
else
statement started after closing if
f.FileExists
← No object defined for 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.