簡體   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