Visual Basic® Scripting Edition
|| Language Reference |
Conditionally executes a group of statements, depending on the value of an expression.
If condition Then statements[Else elsestatements ]
Or, you can use the following, more versatile syntax:
If condition Then
[ElseIf condition-n Then
[elseifstatements]] . . .
The If...Then...Else statement syntax has these parts:
Part Description condition One or more of the following two types of expressions:
An expression of the form TypeOf objectname Is objecttype. The objectname is any object reference and objecttype is any valid object type. The expression is True if objectname is of the object type specified by objecttype; otherwise it is False.
statements One or more statements separated by colons; executed if condition is True. condition-n Same as condition. elseifstatements One or more statements executed if the associated condition-n is True. elsestatements One or more statements executed if no previous condition or condition-n expression is True.
You can use the single-line form (first syntax) for short, simple tests. However, the block form (second syntax) provides more structure and flexibility than the single-line form and is usually easier to read, maintain, and debug.
Note With the single-line syntax, it is possible to have multiple statements executed as the result of an If...Then decision, but they must all be on the same line and separated by colons, as in the following statement:
If A > 10 Then A = A + 1 : B = B + A : C = C + B
When executing a block If (second syntax), condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf (if any) is evaluated in turn. When a True condition is found, the statements following the associated Then are executed. If none of the ElseIf statements are True (or there are no ElseIf clauses), the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following End If.
The Else and ElseIf clauses are both optional. You can have as many ElseIf statements as you want in a block If, but none can appear after the Else clause. Block If statements can be nested; that is, contained within one another.
What follows the Then keyword is examined to determine whether or not a statement is a block If. If anything other than a comment appears after Then on the same line, the statement is treated as a single-line If statement.
A block If statement must be the first statement on a line. The block If must end with an End If statement.
|file: /Techref/language/asp/vbs/vbscript/379.htm, 6KB, , updated: 2001/12/5 10:48, local time: 2018/6/21 23:11,
|©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/techref/language/asp/vbs/vbscript/379.htm"> Microsoft® Visual Basic® Scripting Edition </A>
|Did you find what you needed?|
PICList 2018 contributors:
o List host: MIT, Site host massmind.org, Top posters @20180621 RussellMc, Van Horn, David, Sean Breheny, Isaac M. Bavaresco, Neil, David C Brown, Bob Blick, Denny Esterline, Brent Brown, James Cameron,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!