我正在用vba写一个条件语句
if(userID = 1 or userID = 2 or userID = 3 or userID = 4) then
...
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更快,更清洁的方法来做到这一点.就像是
if(userID in (1,2,3,4)) then
...
Run Code Online (Sandbox Code Playgroud)
谢谢
Mic*_*Sim 10
另一种选择是:
select case userID
case 1,2,3,4,5,6
' do something
end select
Run Code Online (Sandbox Code Playgroud)
它传达了if ... then ... else构造的意义非常好.
其他方式
If UBound(Filter(Array(1, 2, 3, 4, 5, 6), UserID)) > -1 Then
Run Code Online (Sandbox Code Playgroud)
Filter返回一个匹配的数组.如果没有匹配,则ubound = -1.