一个条件,多个事件 [英] one condition, multiple events
问题描述
我试图找出如何使用.vbs只使用一个条件来发生多个事件。 (这里我试图使用case语句。)有没有这样的命令,还是我必须重写每一行的命令? (这是通过在以前的代码行已经被激活的方式在记事本上键入。)
I'm trying to figure out how to make multiple events happen with just one condition using .vbs. (Here I attempted to use the case statement.) Is there a such command, or do I have to rewrite the command for every line? (This is to be typed on notepad by having it already activated in previous lines of code.)
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 True
,增强使用选择案例
切换:
I think you are looking for Select Case True
, an enhanced use of the Select Case
switch:
age = inputbox("I was wondering how old you are.")
Select Case True
' first handle incorrect input
Case (not IsNumeric(age))
WshShell.SendKeys "You silly, you have to enter a number.{ENTER}"
' You can combine cases with a comma:
Case (age<3), (age>120)
WshShell.SendKeys "No, no. I don't think that is correct.{ENTER}"
' Now evaluate correct cases
Case (age>24)
WshShell.SendKeys "I see you are " & age - 24 & " years older than me.{ENTER}"
Case (age<24)
WshShell.SendKeys "I see you are " & 24 - age &" years younger than me.{ENTER}"
Case (age=24)
WshShell.SendKeys "Wow were the same age!{ENTER}"
' Alternatively you can use the Case Else to capture all rest cases
Case Else
' But as all other cases handling the input this should never be reached for this snippet
WshShell.SendKeys "Woah, how do you get here? The Universe Collapse Sequence is now initiated.{ENTER}"
End Select
我提出了一些额外的情况,向您展示此增强型交换机的强大功能。与相反,如果一个And b Then
语句,逗号的情况会短暂。
I put in some extra cases to show you the power of this enhanced switch. In contrary to If a And b Then
statements, the cases with comma's are shortcircuited.
这篇关于一个条件,多个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!