VBS TUTORIAL: VBScript statement-select Case Statement _vbs

Source: Internet
Author: User
Tags case statement

Select Case Statement
Executes one of several sets of statements based on the value of an expression.

Select Case testexpression
[Case Expressionlist-n
[Statements-n]] . . .
[Case Else Expressionlist-n
[Elsestatements-n]]
End Select

Parameters
Testexpression

An arbitrary numeric or string expression.

Expressionlist-n

An option is required if case appears. A list of the boundaries of one or more expressions.

Statements-n

One or more statements that are executed when the testexpression matches any part of the expressionlist-n.

Elsestatements-n

One or more statements that are executed when testexpression does not match any part of the case clause.

Description
If testexpression matches any case expressionlist expression, executes the statement between this case clause and the next one, and for the last clause, executes the statement between the clause and the end Select, and then the control is transferred to the E The statement after ND Select. If the testexpression matches the expressionlist expression in multiple case clauses, only the first matching statement is executed.

Case Else is used to indicate that if a match is not found between the testexpression and the expressionlist of any other option, the elsestatements is executed. Although not necessary, it is a good idea to put the case Else statement in a Select case block to handle unforeseen testexpression values. If no case expressionlist matches the testexpression and no case Else statement is executed, the statement after the end Select continues.

A Select Case statement can be nested, and each level of nested Select Case statements must have a matching End Select statement.

The following example illustrates how to use the Select Case statement:

Copy Code code as follows:

Dim Color, MyVar
Sub Changebackground (Color)
MyVar = LCase (Color)
Select Case MyVar
Case "Red" Document.bgcolor = "Red"
Case "green" Document.bgcolor = "green"
Case "Blue" Document.bgcolor = "Blue"
Case Else MsgBox "Choose another Color"
End Select
End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.