VBScript | SELECT CASE statement

by Bharat Suneja

Rather than using too many IF-THEN conditions to check a value and take action, you are better off using the SELECT CASE condition. It produces cleaner code and is specifically meant for multiple IF-THEN conditions.

The correct use of SELECT CASE:

Select Case strValue [strValue is the variable you want to evaluate]

Case “John”…

do someting here if strValue = “John”

Case “Paul”…

do someting here if strValue = “Paul”

Case Else [Unlike IF-THEN-ELSE, Select Case has CASE ELSE as the “catch-all”]

do this if strValue does not = “John” or “Paul”

End Select [END SELECT ends the Select Case loop, like END IF for IF-THEN]

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: