Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The use of Select Case statement in VBS

2025-01-19 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 use of Select Case sentences in VBS". Many people will encounter such a dilemma in the operation of actual cases, 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!

Select Case statement

Executes one of several sets of statements based on the value of the expression.

Select Case testexpression

[Case expressionlist-n

[statements-n]]. . .

[Case Else expressionlist-n

[elsestatements-n]]

End Select

Parameters.

Testexpression

Any numeric or string expression.

Expressionlist-n

Required if Case appears. A list of boundaries for one or more expressions.

Statements-n

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

Elsestatements-n

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

Description

If testexpression matches any Case expressionlist expression, the statement between this Case clause and the next Case clause is executed, for the last clause, the statement between that clause and End Select is executed, and control is transferred to the statement after End Select. If testexpression matches the expressionlist expression in multiple Case clauses, only the statement after the first match is executed.

Case Else is used to indicate that elsestatements is executed if no match is found between the expressionlist of testexpression and any other Case options. Although not necessary, it is best to place Case Else statements in Select Case blocks to handle unforeseen testexpression values. If no Case expressionlist matches testexpression and there is no Case Else statement, the statement after End Select continues.

Select Case statements can be nested, and each layer of nested Select Case statements must have matching End Select statements.

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

The copy code is 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

This is the end of the content of "the use of Select Case sentences in VBS". 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report