www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons VBScript If Statement Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Sometimes in our programs we want to execute some code depending upon the result of some condition.

VBScript If statement is used to make decisions in our code depending upon the result of some condition.

For example we want to greet the visitors of our website with appropriate messages; good morning, if it is morning, good evening if it is evening, etc.

Here is the syntax of the If statement:

If [condition] Then
' VBScript code to execute if the condition is true
End If

We write the keyword If followed by a condition. A condition is any VBScript expression that evaluates to true or false. A condition is usually written by using one of the several comparison operators available in VBScript. After the condition we write the keyword Then and then we write the code that we wish to be executed in case the condition turns out to be true. Finally we write the words End If to end the If code block.

Here is an example:

<script type="text/vbscript">
Dim a
Dim b
a = 10
b = 20
If a < b Then
document.write("A is less than B")
End If
</script>

Here is the output:

A is less than B


The If statement in the above code checks if the value of the variable a is less than b and then outputs the text "A is less than B", if the condition is met.

VBScript Comparison Operators
Following table lists the comparison operators available in VBScript:

Operator Description
= Is equal to
checks the equality of the operands
<> Is not equal to
checks the inequality of the operands
> Greater than
checks if the value on the left hand side is greater than the value on the right hand side
>= Greater than or equal to
checks if the value on the left hand side is greater than or equal to the value on the right hand side
< Less than
checks if the value on the left hand side is less than the value on the right hand side
<= Less than or equal to
checks if the value on the left hand side is less than or equal to the value on the right hand side

Next >>> Lesson No. 9: VBScript If Else and Elseif




Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.