出现错误“预计在第 34 行结束”

出现错误“预计在第 34 行结束”

代码如下:

Set Sapi = Wscript.CreateObject("SAPI.SpVoice")
set wshshell = wscript.CreateObject("wscript.shell")

dim Input
Sapi.speak "Please type, what you want to open?"
Input=inputbox ("Please type, what you want to open.")
If Input = "youtube" OR Input = "Youtube" then
    Sapi.speak "Opening youtube"
    wshshell.run "www.youtube.com"
  else If Input = "instructables" OR Input = "Instructables" then
    Sapi.speak "Opening instructables"
    wshshell.run "www.instructables.com"
  else If Input = "google" OR Input = "Google" then
    Sapi.speak "Opening google"
    wshshell.run "www.google.com"
  else If Input = "command prompt" OR Input = "Command prompt" then
    Sapi.speak "Opening command prompt"
    wshshell.run "cmd"
  else If Input = "calculator" OR Input = "Calculator" then
    Sapi.speak "Opening calculator"
    wshshell.run "calc"
  else If Input = "notepad" OR Input = "Notepad" then
    Sapi.speak "Opening notepad"
    wshshell.run "notepad"
  else If Input = "calculator" OR Input = "Calculator" then
    Sapi.speak "Opening calculator"
    wshshell.run "calc"
  else If Input = "oof" OR Input = "OOF" then
    Sapi.speak "roblox,,, really?"
  else If Input = "HERE" OR Input = "HERE" then
    wshshell.run "HERE"
  else If InStr(Input, "search google") > 0 Then
    Process.Start("www.google.com/#q=" & Input)
  else Sapi.speak "I don't recognize your input, Please try something else"
end If

我每次尝试运行它时都会出现错误。

答案1

“Else”和“If”之间没有空格,是一个单词“Elseif”。

https://www.tutorialspoint.com/vbscript/vbscript_if_elseif_else_statement.htm

因此你的代码看起来应该是这样的:

Set Sapi = Wscript.CreateObject("SAPI.SpVoice")
set wshshell = wscript.CreateObject("wscript.shell")

dim Input
Sapi.speak "Please type, what you want to open?"
Input=inputbox ("Please type, what you want to open.")
If Input = "youtube" OR Input = "Youtube" then
    Sapi.speak "Opening youtube"
    wshshell.run "www.youtube.com"
  elseIf Input = "instructables" OR Input = "Instructables" then
    Sapi.speak "Opening instructables"
    wshshell.run "www.instructables.com"
  elseIf Input = "google" OR Input = "Google" then
    Sapi.speak "Opening google"
    wshshell.run "www.google.com"
  elseIf Input = "command prompt" OR Input = "Command prompt" then
    Sapi.speak "Opening command prompt"
    wshshell.run "cmd"
  elseIf Input = "calculator" OR Input = "Calculator" then
    Sapi.speak "Opening calculator"
    wshshell.run "calc"
  elseIf Input = "notepad" OR Input = "Notepad" then
    Sapi.speak "Opening notepad"
    wshshell.run "notepad"
  elseIf Input = "calculator" OR Input = "Calculator" then
    Sapi.speak "Opening calculator"
    wshshell.run "calc"
  elseIf Input = "oof" OR Input = "OOF" then
    Sapi.speak "roblox,,, really?"
  elseIf Input = "HERE" OR Input = "HERE" then
    wshshell.run "HERE"
  elseIf InStr(Input, "search google") > 0 Then
    Process.Start("www.google.com/#q=" & Input)
  else Sapi.speak "I don't recognize your input, Please try something else"
End If

相关内容