问题
Seems If I stack the Cases together they don't work as one.
Since VB.NET Cases don't require the use of Exit Select
/ Return it seems to automatically put that every time a new Case is detected under it?
Dim Test as Integer = 12
Select Case Test
Case 11
Case 12
Case 13
MsgBox.Show("Could be 11 or 12 or 13?")
End Select
It doesn't seem to work only 13 works..
Gotta always remember this rule that you can't stack Cases like this from now on
It's not easy to remember it when porting applications.`
回答1:
Your understanding is correct. VB will not "fall through".
Specify a single Case
and separate each expression with a comma:
Select Case Test
Case 11, 12, 13
MsgBox.Show("Could be 11 or 12 or 13?")
End Select
Alternatively, you could use a range with the To
keyword to accomplish the same thing:
Select Case Test
Case 11 To 13
MsgBox.Show("Could be 11 or 12 or 13?")
End Select
For more information, see the documentation.
来源:https://stackoverflow.com/questions/23795886/vb-net-stacking-select-case-statements-together-like-in-switch-c-java