Select Case cmd
case "ONE": MsgBox "one"
case "TWO": MsgBox "two"
case "THREE": MsgBox "three"
End select
我的要求是,如果cmd = "ONE"
我需要"one"
然后"two"
不过目前显示我正在"one"
显示,然后程序被打破了选择案例...
Select Case cmd
case "ONE": MsgBox "one"
case "TWO": MsgBox "two"
case "THREE": MsgBox "three"
End select
我的要求是,如果cmd = "ONE"
我需要"one"
然后"two"
不过目前显示我正在"one"
显示,然后程序被打破了选择案例...
Select Case cmd
case "ONE", "TWO":
if cmd = "ONE" THEN
MsgBox "one"
end if
MsgBox "two"
case "THREE": MsgBox "three"
End select
请记住我的切入点,以防在这种情况下“ONE”不会打印任何内容... – 2009-10-12 21:12:14
我正在尝试帮助先生,修复。 – manji 2009-10-12 21:22:01
不错的一个!该语法为我工作! :) – 2009-10-12 21:51:13
一些如果可以做这项工作:
If cmd = "ONE" Then
MsgBox "one"
cmd = "TWO"
End If
If cmd = "TWO" Then
MsgBox "two"
cmd = "THREE"
End If
If Cmd = "THREE" Then
MsgBox "three"
End If
不错的解决方法!我会建议这个答案:) – seadoggie01 2017-05-04 18:51:12
这是设计。 http://msdn.microsoft.com/en-us/library/ee177199%28PROT.10%29.aspx
您可以尝试使用'goto'或过程调用来解决它。
好!我可以做一些事情,比如输入大写“ONE”:做一些处理,然后说GOTO case“TWO”或者在“TWO”语句的情况下添加一些标签。 – 2009-10-12 21:11:36
是的,但它会非常难看且非常难以调试(并且任何继承代码的人都不会高兴不得不通过“意大利面条代码”)。 – 2009-10-12 21:39:35
你只需要很长的路要走。
Select Case cmd
case "ONE": MsgBox "one"
MsgBox "two"
MsgBox "three"
case "TWO": MsgBox "two"
MsgBox "three"
case "THREE": MsgBox "three"
End select
为什么使用Select Case来做这件事?你所做的只是打印“cmd”值的小写版本。
If cmd = "ONE" Then
MsgBox LCase$(cmd)
MsgBox "two"
Else
Msgbox LCase$(cmd)
End If
其实我只是为了描述目的而显示小写字母,实际上在这些情况下将会有代码写成。我想要的条件是如果程序通过cmd =“ONE”进入,它应该在“ONE”中执行一些代码然后穿过'到'两个'... – 2009-10-16 13:30:39
GoTo会工作的很好,我想。
Select Case cmd
Case "ONE"
MsgBox "one"
GoTo AfterONE:
Case "TWO"
AfterONE:
MsgBox "two"
Case "THREE"
MsgBox "three"
End Select
它的工作原理;我测试了它。
如果cmd =“two”会发生什么? – Gratzy 2009-10-12 21:06:04
我_think_这是由设计;该代码会在案例中的最后一条语句后自动跳转到最后。相反,您将不得不围绕它编程(例如使用过程)。 – 2009-10-12 21:06:05
@Gratzy:如果cmd =“two”,它应该默认打印“two”并突然出现......我想这是VBA中的默认行为。我认为VBA隐含地在每个case后添加“break”语句,即I想绕过。 – 2009-10-12 21:09:25