Working with conditional statements
Program execution
Use conditional statements and circular statements to control the flow of scripts. Use conditional statements to write VBScript code for judging and repeating operations. The following conditional statements can be used in VBScript:
If ... Then ... Else statement
Select Case Statement
Use If ... Then ... Else to judge
If ... Then ... The Else statement evaluates to whether the condition is True or False and specifies the statement to run based on the result of the calculation. Typically, a condition is an expression that compares a value or a variable using a comparison operator. For more information about comparison operators, see comparison operators. If ... Then ... The Else statement can be nested as needed.
Run statement when condition is True
To run a single-line statement when the condition is True, use the If ... Then ... The single line syntax of the Else statement. The following example demonstrates the Single-line syntax. Please note that this example omits the keyword Else.
Sub Fixdate ()
Dim mydate
MyDate = #2/13/95#
If MyDate < now Then mydate = Now
End Sub
To run multiple lines of code, you must use multiple lines (or blocks) of syntax. The MultiRow (or block) syntax contains the end If statement, as follows:
Sub Alertuser (value)
If value = 0 Then
Alertlabel.forecolor = vbred
AlertLabel.Font.Bold = True
AlertLabel.Font.Italic = True
End If
End Sub
Run certain statements when the condition is True and False
You can use the If ... Then ... Else statement defines two executable statement blocks: A block of statements runs when the condition is True, and another block of statements runs when False.
Sub Alertuser (value)
If value = 0 Then
Alertlabel.forecolor = vbred
AlertLabel.Font.Bold = True
AlertLabel.Font.Italic = True
Else
Alertlabel.forecolor = Vbblack
AlertLabel.Font.Bold = False
AlertLabel.Font.Italic = False
End If
End Sub
To judge a number of conditions
If ... Then ... A variant of the ELSE statement allows you to select from multiple conditions, that is, to add a ElseIf clause to augment the If ... Then ... Else statement, which allows you to control the process based on a variety of possible programs. For example:
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