Conditional statements are used to perform different actions for different decisions.
In VBScript we have four conditional statements:
if statement - executes a set of code when a condition is true
if...then...else statement - select one of two sets of lines to execute
if...then...elseif statement - select one of many sets of lines to execute
select case statement - select one of many sets of lines to execute
--------------------------------------------------------------------------------
If....Then.....Else
Use the If...Then...Else statement if you want to
execute some code if a condition is true
select one of two blocks of code to execute
If you want to execute only one statement when a condition is true, you can write the code on one line:
if i=10 Then msgbox "Hello"
There is no ..else.. in this syntax. You just tell the code to perform one action if a condition is true (in this case if i=10).
If you want to execute more than one statement when a condition is true, you must put each statement on separate lines, and end the statement with the keyword "End If":
if i=10 Then
msgbox "Hello"
i = i+1
end If
There is no ..else.. in the example above either. You just tell the code to perform multiple actions if the condition is true.
If you want to execute a statement if a condition is true and execute another statement if the condition is not true, you must add the "Else" keyword.
Wednesday, May 6, 2009
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment