我想弄清楚如何使用.vbs只有一個條件發生多個事件。 (這裏我試圖使用case語句。)是否有這樣的命令,還是我必須爲每一行重寫命令? (這是要通過具有它已經在以前的代碼行激活記事本上鍵入。)一個條件,多個事件
msgbox("I was woundering how old you are.")
age=inputbox("Type age here.",,"")
Select Case age
Case age>24
x=age-24
WshShell.SendKeys "I see you are "&x&" years older than me."
WshShell.SendKeys "{ENTER}"
Case age<24
x=24-age
WshShell.SendKeys "I see you are "&x&" years younger than me."
WshShell.SendKeys "{ENTER}"
Case age=24
WshShell.SendKeys "Wow were the same age!"
WshShell.SendKeys "{ENTER} "
End Select
封裝是一個很好的建議,但你的代碼是越野車。因爲你使用'Select Case age'和'age> 24','age <24'和'age = 24',所以你正在評估'{integer} = {True | False}'總是導致'False',被執行。 – AutomatedChaos
啊,當然。在這種情況下,「If..ElseIf..Else」會更適合。固定。 –
這是我的結果:'age = inputbox(「Type age here。」,,「」) 如果年齡> 24然後 text =「我看到你了」&(24歲)&「比我年長。 「 ElseIf <24然後 text =「我看見你了」&(24歲)&「比我年輕」。 ElseIf age = 24 Then text =「哇是同齡人!」 End If msgbox text WScript.Sleep 1000 WshShell.SendKeys text&「{ENTER ENTER」「 –