The VBScript Network and Systems Administrator's Cafe

May 9 2008   5:54PM GMT

VBScript Statements: Explanation of Select … Case

Jerry Lees Jerry Lees Profile: Jerry Lees

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

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: