- VBScript Tutorial
- VBScript - Home
- VBScript - Overview
- VBScript - Syntax
- VBScript - Enabling
- VBScript - Placement
- VBScript - Variables
- VBScript - Constants
- VBScript - Operators
- VBScript - Decisions
- VBScript - Loops
- VBScript - Events
- VBScript - Cookies
- VBScript - Numbers
- VBScript - Strings
- VBScript - Arrays
- VBScript - Date
- VBScript Advanced
- VBScript - Procedures
- VBScript - Dialog Boxes
- VBScript - Object Oriented
- VBScript - Reg Expressions
- VBScript - Error Handling
- VBScript - Misc Statements
- VBScript Useful Resources
- VBScript - Questions and Answers
- VBScript - Quick Guide
- VBScript - Useful Resources
- VBScript - Discussion
Comparison Operators in VBScript
Following table shows all the Comparison operators supported by VBScript language. Assume variable A holds 10 and variable B holds 20, then:
Operator | Description | Example |
---|---|---|
= | Checks if the value of two operands are equal or not, if yes then condition becomes true. | (A == B) is False. |
<> | Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. | (A <> B) is True. |
> | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (A > B) is False. |
< | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (A < B) is True. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (A >= B) is False. |
<= | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (A <= B) is True. |
Example
Try the following example to understand all the Comparison operators available in VBScript:
<!DOCTYPE html> <html> <body> <script language="vbscript" type="text/vbscript"> Dim a : a = 10 Dim b : b = 20 Dim c If a=b Then Document.write ("Operator Line 1 : True") Document.write ("<br></br>") 'Inserting a Line Break for readability Else Document.write ("Operator Line 1 : False") Document.write ("<br></br>") 'Inserting a Line Break for readability End If If a<>b Then Document.write ("Operator Line 2 : True") Document.write ("<br></br>") Else Document.write ("Operator Line 2 : False") Document.write ("<br></br>") End If If a>b Then Document.write ("Operator Line 3 : True") Document.write ("<br></br>") Else Document.write ("Operator Line 3 : False") Document.write ("<br></br>") End If If a<b Then Document.write ("Operator Line 4 : True") Document.write ("<br></br>") Else Document.write ("Operator Line 4 : False") Document.write ("<br></br>") End If If a>=b Then Document.write ("Operator Line 5 : True") Document.write ("<br></br>") Else Document.write ("Operator Line 5 : False") Document.write ("<br></br>") End If If a<=b Then Document.write ("Operator Line 6 : True") Document.write ("<br></br>") Else Document.write ("Operator Line 6 : False") Document.write ("<br></br>") End If </script> </body> </html>
When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result:
Operator Line 1 : False Operator Line 2 : True Operator Line 3 : False Operator Line 4 : True Operator Line 5 : False Operator Line 6 : True
vbscript_operators.htm
Advertisements