- The Fundamentals of VBScript
- VBScript Versus VB
- Creating Variables in VBScript
- Concatenating Strings
- Arrays and Loops
- Resizing Arrays
- Inequality Operators
- Conditional Statements
- Select Case Statements
- Working with Arguments
- Beware of Types
- Event Procedure Naming Syntax
- Server-Side Events
- Local Variables
- Script-Level Variables
A conditional statement is one that passes control to another statement when it evaluates to true. VBScript supports these statements: If...Then, If...Then...Else, If...Then...ElseIf...Else, and Select Case statements.
The following example demonstrates the syntax for a simple If...Then statement that executes one line of code and another that executes multiple lines of code.
<SCRIPT LANGUAGE=VBScript> If x = 5 Then y = 9 If x = 5 Then 'Send out an alert message Alert "x = 5, it really does!" y = 9 End If </SCRIPT>
Notice that the If...Then statement that executes multiple lines of code terminates with an End...If line.
The next example shows you how to write an If...Then...Else statement. You use an If...Then...Else statement when you need to have alternate code execute if the If condition is not met.
<SCRIPT LANGUAGE=VBScript> If x = 5 Then y =0 i = 14 Else y = 9 i = 200 End If </SCRIPT>
You use the If...Then...ElseIf statement to test for multiple conditions. The following example shows you how to us the If...Then...ElseIf statement:
<SCRIPT LANGUAGE=VBScript> If y > 10 Then x = x + y ElseIf y > 100 Then x = x + x + y Else x = x End If </SCRIPT>
Commenting in VBScript
You comment a line in VBScript by using the single quote character, ', at the beginning of the line. Also, remember you can comment only lines that appear within a set of <SCRIPT> tags.
The following shows a commented line:
<SCRIPT LANGUAGE=VBScript> 'Declare a variable Dim y </SCRIPT>
Similarly, you write comments within in line script tags as follows
<% 'Declare a variable Dim y %>