- 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 - 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
VBScript Logical Operators
VBScript supports the following logical operators −
Assume variable A holds 10 and variable B holds 0, then −
| Operator | Description | Example |
|---|---|---|
| AND | Called Logical AND operator. If both the conditions are True, then Expression becomes True. | a<>0 AND b<>0 is False. |
| OR | Called Logical OR Operator. If any of the two conditions is True, then condition becomes True. | a<>0 OR b<>0 is true. |
| NOT | Called Logical NOT Operator. It reverses the logical state of its operand. If a condition is True, then the Logical NOT operator will make it False. | NOT(a<>0 OR b<>0) is false. |
| XOR | Called Logical Exclusion. It is the combination of NOT and OR Operator. If one, and only one, of the expressions evaluates to True, result is True. | (a<>0 XOR b<>0) is true. |
Example
Try the following example to understand all the Logical operators available in VBScript −
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
Dim a : a = 10
Dim b : b = 0
Dim c
If a<>0 AND b<>0 Then
Document.write ("AND Operator Result is : True")
Document.write ("<br></br>") 'Inserting a Line Break for readability
Else
Document.write ("AND Operator Result is : False")
Document.write ("<br></br>") 'Inserting a Line Break for readability
End If
If a<>0 OR b<>0 Then
Document.write ("OR Operator Result is : True")
Document.write ("<br></br>")
Else
Document.write ("OR Operator Result is : False")
Document.write ("<br></br>")
End If
If NOT(a<>0 OR b<>0) Then
Document.write ("NOT Operator Result is : True")
Document.write ("<br></br>")
Else
Document.write ("NOT Operator Result is : False")
Document.write ("<br></br>")
End If
If (a<>0 XOR b<>0) Then
Document.write ("XOR Operator Result is : True")
Document.write ("<br></br>")
Else
Document.write ("XOR Operator Result is : 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 −
AND Operator Result is : False OR Operator Result is : True NOT Operator Result is : False XOR Operator Result is : True
vbscript_operators.htm
Advertisements