The VBScript Network and Systems Administrator's Cafe

May 9 2008   5:54PM GMT

VBScript Statements: Explanation of Select … Case



Posted by: Jerry Lees
Functions, VBScript, VBScript Statements, vbscriptstatements

The Select … Case VBScript statement is a very powerful way to easily preform specific actions based on a comparison of a variable to a series of cases you specify, plus it allows for the fact that NONE of the cases apply with an optional case else condition. The Select Case statement is often a better solution then a if…Then…Else if when you have more than 2 conditions that could apply.

Consider the following code snippet to check if a number is positive or negative:

Function TestNumber(Number)

Select case Number
Case Number > 0
TestNumber = “Positive”
Case Number < 0
TestNumber = “Negative”
Case Else
TestNumber = “Zero”
End Select

Comment on this Post

Leave a comment: