什么是vbscript中条件语句的最短表达式?
问题描述:
例如,如果我有以下代码:什么是vbscript中条件语句的最短表达式?
dim a
if a = 0 then
b = 1
else
b = 2
end if
我可以缩短这个代码,而无需牺牲其有效性?谢谢。
答
据我所知,有没有办法缩短这个直接的代码,但你可以做:
dim a,b : a =0 : b=1 ''set a = 0 & b = 1 directly
'' Now as per your requirement 'a' value might change in script flow then you can set value as
If a > 0 then b= 2
希望这有助于.........
答
对于这个特定的情况下,你可以写一个辅助函数来模仿VBA IIf功能:
Function IIf(expr, truepart, falsepart)
If expr Then
IIf = truepart
Else
IIf = falsepart
End If
End Function
b = IIf(a=0, 1, 2)
任何想到这里: B =(α= 0)* 1 +(一 0)* 2? – 2012-07-30 23:44:31