“选择案例”的问题
我在下面写了以下部分。 调试时,我看到我输入了第一个案例,没问题。 我的问题是第二个案例 - 它没有输入并转到错误消息。
我做错了什么?
Select Case Data_Rate
Case "1", "2", "5.5", "11", "6", "9", "12", "18", "24", "36", "48", "54"
a = Data_Rate
Select Case Date_Rate
Case "1"
b = 2
Case "2", "5.5", "11"
b = 1
Case Else:
MsgBox ("ERROR - Data_Rate")
End Select
Case "0", "1", "2", "3", "4", "5", "6", "7"
a = 3
Case Else:
MsgBox ("ERROR - Data_Rate")
End Select
i wrote the following section below.
when debugging, i see that i enter the first Case okay.
my problem is with the second Case - it does not enter it and goes to the error messege.
what do i do wrong?
Select Case Data_Rate
Case "1", "2", "5.5", "11", "6", "9", "12", "18", "24", "36", "48", "54"
a = Data_Rate
Select Case Date_Rate
Case "1"
b = 2
Case "2", "5.5", "11"
b = 1
Case Else:
MsgBox ("ERROR - Data_Rate")
End Select
Case "0", "1", "2", "3", "4", "5", "6", "7"
a = 3
Case Else:
MsgBox ("ERROR - Data_Rate")
End Select
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于像 1、2 和 6 这样的值,它总是只执行第一个 case,
我的 case 语句就像一堆 if/else if 语句。
只执行一个块,
不执行多个块
For values like 1, 2, and 6 that are in both, it will always only execute the first case
I case statement is like a bunch of if/else if statements.
Only one block is executed
Not multiple blocks
这是您上面粘贴的实际代码吗?
如果是这样,可能是因为您将“datE_rate”而不是“datA_rate”作为嵌套 Select 语句的值。
如果没有,或者即使是这样,您可能还需要区分错误消息,以便更清楚地确定是内部 Select 失败还是外部 Select 失败。
编辑:
另外,我认为您没有使用 Option Explicit。如果是的话,它会发现您错误地使用了 Date_Rate,除非您确实有这样的变量。
Is that your actual code pasted in above?
If so, it may be because you have "datE_rate" instead of "datA_rate" as the value for your nested Select statement.
If not, or even if so, you may also want to differentiate your error messages so it's clearer whether it's the inner or outer Select that is failing.
Edit:
Also, I don't think you are using Option Explicit. If you were, it would have caught your mistaken use of Date_Rate, unless you actually do have such a variable.