In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "the usage of VBS conditional sentences". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Conditional statements and loop statements control the flow of scripts. Conditional statements allow you to write VBScript code that performs judgments and repeated operations. The following conditional statements are available in VBScript:
If... Then... Else statement
Select Case statement
Use If... Then... Else to judge
If... Then... The Else statement evaluates whether a condition is True or False and specifies which statement to run based on the evaluation result. Typically, conditions are expressions that compare values or variables using comparison operators. For more information about comparison operators, see Comparison Operators. If... Then... Else statements can be nested as desired.
Run statement when condition is True
To run a single-line statement when the condition is True, use If... Then... Single-line syntax for Else statements. The following example demonstrates single-line syntax. Note that the keyword Else is omitted from this example.
Sub FixDate() Dim myDate myDate = #2/13/95# If myDate < Now Then myDate = Now End Sub
To run multiline code, you must use multiline (or block) syntax. The multiline (or block) syntax contains an End If statement, as follows:
Sub AlertUser(value) If value = 0 Then AlertLabel.ForeColor = vbRed AlertLabel.Font.Bold = True AlertLabel.Font.Italic = True If End Sub Runs certain statements when the condition is True and False, respectively
You can use If... Then... An Else statement defines two executable statement blocks: one statement block runs when the condition is True, and another statement block runs 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
If... Then... A variant of the Else statement that allows you to choose from multiple conditions is to add an ElseIf clause to extend the If... Then... Else statements enable you to control program flow based on a variety of possibilities. 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 out of range! " End If
You can add any number of ElseIf clauses to provide multiple choices. Using multiple ElseIf clauses often becomes cumbersome. A better way to select among multiple conditions is to use the Select Case statement.
Use Select Case to judge
The Select Case structure provides an If... Then... A variation of the ElseIf construct, which allows you to select one of several statement blocks to execute. The Select Case statement provides the same functionality as the If... Then... Else statements are similar, but can make the code simpler and easier to read.
The Select Case construct begins with a simple test expression that evaluates only once. The result of the expression is compared to the value of each Case in the structure. If there is a match, the statement block associated with the Case is executed. Example code is as follows:
Select Case Document.Form1.CardType.Options(SelectedIndex).Text Case "MasterCard" DisplayMCLogo ValidateMCAccount Case "Visa" DisplayVisaLogo ValidateVisaAccount Case "American Express" DisplayAMEXCOLogo ValidateAMEXCOAccount Case Else DisplayUnknownImage PromptAgainEnd Select
Note that the Select Case construct evaluates only one expression at the beginning (only once), whereas If... Then... The ElseIf construct evaluates expressions for each ElseIf statement, which can vary. You can use the Select Case construct instead of If... only if each ElseIf statement evaluates the same expression. Then... ElseIf structure.
undefined
The content of "Usage of VBS Conditional Statements" is introduced here. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.