繁体   English   中英

我收到“ Else”错误800A03EA

[英]I'm getting error 800A03EA with “Else”

问题在第十四行。 否则是语法错误,(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

这里需要进行两项更改。

  1. else语句在关闭后开始, if
  2. 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM