Sub ss()
Dim a As Double
a = 6.99999999
Select Case a
Case 0 To 7:
MsgBox "ok"
Case Else:
MsgBox "no"
End Select
End Sub
Case 0 to 7
会检查a >= 0 and a <= 7
。但我想要的是a >= 0 and a < 7
。
我也试过Case Is >=0, Is < 7
。
如何在Select Case
?
a = 6.99999999
应该会导致“ok”a = 7
应导致“否”答案 0 :(得分:2)
select case true
case a >= 0 and a < 7
MsgBox "ok"
case else
MsgBox "no"
end select
但是,除非您有两个以上的条件,否则我建议您改用If
。
答案 1 :(得分:0)
Sub ss()
Dim a
a = 7
Select Case a
Case 7:
MsgBox "no"
Case 0 To 7:
MsgBox "ok"
Case Else:
MsgBox "no"
End Select
End Sub
答案 2 :(得分:0)
Sub ss()
Dim a As Double
a = 6.99999999
Select Case a
Case 0 To 7:
If a = 7 Then
MsgBox "no"
Else
MsgBox "ok"
End If
Case Else:
MsgBox "no"
End Select
End Sub
我终于找到了解决方案。谢谢大家!