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
2009-07-14 10:03:26
Gary,Thanks a lot.Since i am just a beginner,got some probs with getting used to vbscripts.
2009-07-14 10:06:54
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
2009-07-14 10:06:31
Ghostdog,I just got another doubt.Are there any break statements associated with each case??
2009-07-14 10:09:45
Nope no break in VBScript, often wondered why it exists in other languages?
MrTelly
2009-07-14 10:17:19
@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
2009-07-14 10:33:49
@Maddy, in response to your questions, as MrTelly said, no breaks in case select, but you can do "break" in for loops.
ghostdog74
2009-07-14 11:04:58