views:

76

answers:

2

Can anyone please tell me how to implement select statements in VBScript, similar to switch statement in C? It would be great if you provided some examples as I'm pretty new to VBScript. Thanks.

+8  A: 
Select Case foo
    Case 1
       MsgBox "1"
    Case 2, 3
       MsgBox "2 or 3"
    Case Else
       MsgBox "Something else"
End Select
Gary McGill
Gary,Thanks a lot.Since i am just a beginner,got some probs with getting used to vbscripts.
A: 

example only

 Select Case strMyVariable
      Case "One"     Wscript.Echo "1"
      Case "Two"     Wscript.Echo "2"
      Case "Three"   Wscript.Echo "3"
      Case Else      Wscript.Echo "Wrong"
 End Select
ghostdog74
Ghostdog,I just got another doubt.Are there any break statements associated with each case??
Nope no break in VBScript, often wondered why it exists in other languages?
MrTelly
@MrTelly: Goes back to old C (pre C++) days where any small opporunity to save a few bytes in the code were considered worthwhile despite the potential spaggetti it could create.
AnthonyWJones
Thanks everybody
@Maddy, in response to your questions, as MrTelly said, no breaks in case select, but you can do "break" in for loops.
ghostdog74