In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use conditional statements in VBScript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Control program execution
Conditional statements and loop statements can be used to control the flow of Script. Conditional statements can be used to write VBScript code that makes judgments and repeats operations. The following conditional statements can be used in VBScript:
If...Then...Else statement
Select Case statement
Use If...Then...Else to judge
The If...Then...Else statement is used to evaluate whether the condition is True or False and to specify the statement to run based on the result of the calculation. Typically, the condition is an expression that uses a comparison operator to compare a value or variable. For more information about comparison operators, see comparison operators. If...Then...Else statements can be nested as needed.
Run the statement when the condition is True
To run a single-line statement when the condition is True, use the single-line syntax of the If...Then...Else statement. The following example demonstrates one-line syntax. Note that the keyword Else is omitted in this example.
Sub FixDate ()
Dim myDate
MyDate = # 2Compact 13Compact 9pm
If myDate < Now Then myDate = Now
End Sub
To run multiple lines of code, you must use multiline (or block) syntax. The multiline (or block) syntax contains End If statements, 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 define two executable statement blocks using the If...Then...Else statement: one statement block is run when the condition is True, and another statement block is run when the condition is 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
Judge multiple conditions
A variant of the If...Then...Else statement allows you to choose from multiple conditions, that is, adding an ElseIf clause to extend the functionality of the If...Then...Else statement, allowing you to control based on a variety of possible program flows. For example:
Sub ReportValue (value)
If value = 0 Then
MsgBox value
ElseIf value = 1 Then
MsgBox value
ElseIf value = 2 then
Msgbox value
Else
Msgbox "value is out of range!"
End If
You can add as many ElseIf clauses as you want to provide multiple choices. Using multiple ElseIf clauses can often become cumbersome. A better way to choose among multiple conditions is to use the select Case statement.
Use select Case to judge
The select Case structure provides a workaround of the If...Then...ElseIf structure, and you can choose to execute one of multiple statement blocks. Select Case statements provide functions similar to If...Then...Else statements, but can make the code more concise and readable.
The select Case structure uses a simple test expression that evaluates only once at the beginning of it. The result of the expression is compared to the value of each Case in the structure. If there is a match, the block of statements associated with the Case is executed:
Select Case Document.Form1.CardType.Options (selectedIndex). Text
Case "MasterCard"
DisplayMCLogo
ValidateMCAccount
Case "Visa"
DisplayVisaLogo
ValidateVisaAccount
Case "American Express"
DisplayAMEXCOLogo
ValidateAMEXCOAccount
Case Else
DisplayUnknownImage
PromptAgain
End select
Note that the select Case structure evaluates only one expression at the beginning (only once), while the If...Then...ElseIf structure evaluates the expression of each ElseIf statement, which can vary. You can use the select Case structure instead of the If...Then...ElseIf structure only if each ElseIf statement evaluates the same expression.
This is the end of the content of "how to use conditional statements in VBScript". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.