views:

520

answers:

5

Given

Select Case cmd

    case "ONE":   MsgBox "one"

    case "TWO":   MsgBox "two"

    case "THREE": MsgBox "three"

End select

My requirement is if cmd = "ONE" I need "one" and then "two" displayed however currently I am getting "one" displayed and then the program is breaking out of the select case...

+1  A: 
Select Case cmd
    case "ONE", "TWO":   
                  if cmd = "ONE" THEN
                      MsgBox "one"
                  end if
                  MsgBox "two"

    case "THREE": MsgBox "three"

End select
najmeddine
Remember my entry point in case "ONE" which in this case will print nothing...
Kevin Boyd
i'm trying to help sir, fixed.
najmeddine
Nice one! that syntax worked for me! :)
Kevin Boyd
+1  A: 

Some if could do the job:

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
RC
A: 

That is by design. http://msdn.microsoft.com/en-us/library/ee177199%28PROT.10%29.aspx

You could try using 'goto' or procedure calls to get around it.

Michael Todd
Fine! can I do something like enter case "ONE": do some processing and then say GOTO case "TWO" or add some label under the case "TWO" statement.
Kevin Boyd
Yes, but it'd be really ugly and very hard to debug (and anyone inheriting the code will not be pleased having to weed through "spaghetti code").
Michael Todd
A: 

You'll just have to do it the long way.

Select Case cmd

    case "ONE":   MsgBox "one"
                  MsgBox "two"
                  MsgBox "three"

    case "TWO":   MsgBox "two"
                  MsgBox "three"

    case "THREE": MsgBox "three"

End select
Lance Roberts
A: 

Why use Select Case for this? All you're doing is printing the lower-case version of whatever value 'cmd' is.

If cmd = "ONE" Then
  MsgBox LCase$(cmd)
  MsgBox "two"
Else
  Msgbox LCase$(cmd)
End If
JP
Actually I have shown lower case just for a descriptive purposes, practically there will be code written in those cases..and the condition that I want is if the program enters through cmd = "ONE" it should execute some code in "ONE" and then fall thru' to "TWO"...
Kevin Boyd