2013-08-27 52 views
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,使它可以接受更多種類的回覆和消息嗎?如果您熟悉桌面好友,我想創建一個桌面好友,並添加不僅可以在桌面與其交互的部分,還可以與其聊天。

+2

這個問題格式非常糟糕。請嘗試改進您發佈的代碼的格式。你也應該嘗試解釋你想要做什麼。請保留每個問題到自己的主題上,並且不要將屬於不同主題的多個問題包含在同一個問題中。 –

+0

awww ..好的xD哈哈哈對不起xD –

+0

不需要道歉,我們都是新來的StackOverflow一次。只要確保你保持你的下一個問題整潔和專業。 –

回答

4

我認爲這是因爲elseif條件永遠不會成立。我不能大於或等於20,同時小於8。也許你的意思是and i >= 20 OR i < 8 then?另外,我想將它們包括在括號以確保邏輯被計算在正確的順序,如:

Elseif Message = " " and (i >= 20 or i < 8) then 
+0

哇這是快速.. xD非常感謝你xD .. 和你對我的第二個問題有什麼想法嗎? xD關於桌面好友? xD hehehe –

+0

不,我很抱歉我不知道。如果你滿意,你能接受我的答案嗎?我是一個新用戶 - 就像你一樣 - 我試圖建立我的代表。 –

+0

waahh?!..沒有。對不起xD .. –

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 
+0

貌似我需要更多練習xD哈哈哈謝謝xD –

+0

對不起,我修正了代碼; – gariel