0

以下代码有什么问题?它会跳过第三个“else if”,即“你还睡觉吗?”

      Dim Message, i
  Dim strShutdown , lastword, strAbort

   i = Hour (Time)
   Message=InputBox("Hello and WHO might you be?","Virus")

if Message = " "  and i >= 8 and i < 12 then
WScript.Echo "Good Morning."
CreateObject("WScript.Shell").Run """C:\Documents and Settings\Admin\My           Documents\My Files\Designs\Vocaloid\Miku\Shimeji.jar"""
CreateObject("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\hello.vbs"""

Elseif Message = " " and i <= 17 and i >= 12 then
WScript.Echo "Good Afternoon."
CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My    Files\Designs\Vocaloid\Miku\Shimeji.jar"""
CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\hello.vbs"""

Elseif Message = " "  and i >= 18 and i < 20 then
WScript.Echo "Good Evening."
CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\Shimeji.jar"""
CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\hello.vbs"""

Elseif Message = " "  and i >= 20 and i < 8 then
WScript.Echo "Do you even sleep ?"
CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\Shimeji.jar"""
CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\hello.vbs"""

Else 
WScript.Echo "Hmm.... Intruder huh... heh!!."
strShutdown = "shutdown.exe -s -t 60 -f"
set objShell = CreateObject("WScript.Shell")
objShell.Run strShutdown, 0, false
WScript.Sleep 100

lastword= Inputbox("Computer will shutdown in 60 seconds. Any last words?" , "Virus")
If lastword = "stop it" then
WScript.Echo "Hmpf!"
strAbort = "shutdown.exe -a"
set objShell = CreateObject("WScript.Shell")
objShell.Run strAbort, 0, false
else
WScript.Echo "Sorry and Goodbye"
End if
End if

另外,我可以连接到 MS Access 以提供它也接受的更多种类的回复和消息吗?如果您熟悉桌面好友,我想创建一个并添加部分,您不仅可以在桌面上与之交互,还可以与它聊天。

4

2 回答 2

4

我认为这是因为 elseif 条件永远不会成立。i 不能同时大于或等于 20 且小于 8。也许你的意思是and i >= 20 OR i < 8 then?此外,我会将它们包含在括号中,以确保以正确的顺序计算逻辑,例如:

Elseif Message = " "  and (i >= 20 or i < 8) then
于 2013-08-27T16:33:36.327 回答
2

select case在其他地方使用

为了方便起见,我稍微重构了您的代码:

Dim Message
Dim lastword
Dim i
Dim strShutdown
Dim strAbort

strShutdown = "shutdown.exe -s -t 60 -f"
strAbort = "shutdown.exe -a"

i = Hour (Time)
Message = InputBox("Hello and WHO might you be?","Virus")

if Message = " " then
    Select Case i
        case 8, 9, 10, 11
            WScript.Echo "Good Morning."
        case 12, 13, 14, 15, 16, 17
            WScript.Echo "Good Afternoon."
        case 18, 19
            WScript.Echo "Good Evening."
        case else
            WScript.Echo "Do you even sleep ?"
    end select
    CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\Shimeji.jar"""
    CreateObject ("WScript.Shell").Run """C:\Documents and Settings\Admin\My Documents\My Files\Designs\Vocaloid\Miku\hello.vbs"""

Else 
    WScript.Echo "Hmm.... Intruder huh... heh!!."

    set objShell = CreateObject("WScript.Shell")
    objShell.Run strShutdown, 0, false
    WScript.Sleep 100

    lastword= Inputbox("Computer will shutdown in 60 seconds. Any last words?" , "Virus")
    If lastword = "stop it" then
        WScript.Echo "Hmpf!"
        set objShell = CreateObject("WScript.Shell")
        objShell.Run strAbort, 0, false
    else
        WScript.Echo "Sorry and Goodbye"
    End if
End if
于 2013-08-27T16:50:06.070 回答