Vb.net 使用另一个布尔检查选择Case
我知道如何选择一个没有问题的案例。但是:Vb.net 使用另一个布尔检查选择Case,vb.net,select,Vb.net,Select,我知道如何选择一个没有问题的案例。但是: Dim xfld As Boolean Dim ALP As String xfld = True ALP = "D" Select Case ALP Case "A" MsgBox("A") Case "B" MsgBox("B") Case "D" And xfld MsgBox("D1") Case "E" And Not xfld MsgBox("E2
Dim xfld As Boolean
Dim ALP As String
xfld = True
ALP = "D"
Select Case ALP
Case "A"
MsgBox("A")
Case "B"
MsgBox("B")
Case "D" And xfld
MsgBox("D1")
Case "E" And Not xfld
MsgBox("E2")
Case Else
MsgBox("C")
End Select
如果可能的话,我想对案例行进行额外检查。我知道我可以在其中做一个额外的IF语句,但考虑到我正在比较大约10种不同的东西,我宁愿不必在每行中都放一个IF语句(如果xfld,则打印“E2”end IF)
我知道,但不起作用,&编译,但似乎没有做我想要的
有什么想法吗?用逗号“,”代替“和”或“&”
关于OP的两条评论中的任何一条都会起作用。另外,你可以这样做
Dim xfld As Boolean
Dim ALP As String
xfld = True
ALP = "D"
Select Case True
Case ALP = "A"
MsgBox("A")
Case ALP = "B"
MsgBox("B")
Case ALP = "D" AndAlso xfld
MsgBox("D1")
Case ALP = "E" AndAlso Not xfld
MsgBox("E2")
Case Else
MsgBox("C")
End Select
为什么不用if/then替换select case?如果有帮助的话,可以在一个案例中使用select case。这不起作用,因为
xfld
的值在这里没有影响。我总是忘记这样做。我以前看过,但忘了。谢谢
Dim xfld As Boolean
Dim ALP As String
xfld = True
ALP = "D"
Select Case True
Case ALP = "A"
MsgBox("A")
Case ALP = "B"
MsgBox("B")
Case ALP = "D" AndAlso xfld
MsgBox("D1")
Case ALP = "E" AndAlso Not xfld
MsgBox("E2")
Case Else
MsgBox("C")
End Select