选择案例运算符 [英] Select Case Operators
问题描述
我正在使用MS Office 2003 {VBA Excel}
我想知道是否可以在SELECT CASE中使用AND运算符?我已经按照下面的方法进行过尝试,但是无法正常工作.如果没有办法,可以使用IF ... ELSEIF ... ELSE,但我宁愿使用SELECT CASE.
I''m using MS Office 2003 {VBA Excel}
I was wondering if there is a way to use the AND operator in SELECT CASE? I''ve tried it as is {below} but it''s not working like that. If there isn''t a way to do this I can use the IF...ELSEIF...ELSE, but I''d rather use SELECT CASE.
Select Case bMain
Case Is = "Cat" And optLect.Value = True
chkWkTemp.Value = True
Case Is = "Lec" And optCat.Value = True
chkWkTemp.Value = True
Case Else
chkWkTemp.Value = False
End Select
它只是不能那样工作,而且我还没有找到任何方法来确保前两个CASE中的BOTH语句都是正确的,这就是我需要的.
提前谢谢!
给您和您的和平,
Matthew DraGon Stohler
It just doesn''t work like that and I haven''t found any way of making sure BOTH statements in the first 2 CASEs are true, which is what I need for this.
Thanks in advance!
Peace to you and yours,
Matthew DraGon Stohler
推荐答案
您不能使用以下内容:Select ... Case ... End Select
语句中的"Lec" And False
.
正确的陈述是:
You can''t use something like this:"Lec" And False
in theSelect ... Case ... End Select
statement.
The correct statement is:
Select Case optLect.Value
Case True
Select Case bMain
Case Is = "Cat", "Lec"
chkWkTemp.Value = True
Case Else
chkWkTemp.Value = False
End Select
Case False
'?
End Select
或
or
Dim myVal as String
myVal = bMain & Cstr(optLect.Value)
Select Case myVal
Case "LecTrue", "CatTrue"
chkWkTemp.Value = True
Case "LecFalse", "CatFalse"
chkWkTemp.Value = False
End Select
这篇关于选择案例运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!