VBScript Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.01

Comparison and Logic Operations

Part:   1   2 

VB Script Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Data Types and Literals

Variables

Logic Operations

String Operations

Conditional Statements

Arrays

Loop Statements

Functions and Subroutines

Built-in Functions

Variable Inspection

... Table of Contents

This chapter describes:

  • Numeric Comparisons
  • Logical Operations

Notes and samples in this chapter are based Visual Basic 6.0.

Numeric Comparisons

Numeric comparisons are operations that:

  • Operates on two numeric operands.
  • Produces a Boolean value by applying the comparison operation specified by the operator.

There are 6 numeric comparison operations supported in VB:

  • Equal to (=): Resulting (True) if two operands are numerically equal.
  • Not equal to (<>): Resulting (True) if two operands are numerically not equal.
  • Greater than (>): Resulting (True) if the first operand is numerically greater than the second operand.
  • Less than (<): Resulting (True) if the first operand is numerically less than the second operand.
  • Greater than or equal to (>=): Resulting (True) if the first operand is numerically greater than or equal to the second operand.
  • Less than or equal to (<=): Resulting (True) if the first operand is numerically less than or equal to the second operand.

To show you how numeric comparison operations work, I wrote the following script, comparison_operation.html:

<html>
<body>
<!-- comparison_operation.html
   Copyright (c) 2006 by Dr. Herong Yang. http://www.herongyang.com/
-->
<pre>
<script language="vbscript">
   document.writeln(1 = 1)
   document.writeln(1 <> 1)
   document.writeln(9.9999e-1 > 9.99999e-1)
   document.writeln(9.9999e-1 < 1)
   document.writeln(9.9999e-1 >= 0.99999)
   document.writeln(1.00000001 <= 1)
</script>
</pre>
</body>
</html>

Here is the output:

True
False
False
True
True
False

No surprises in the output. But the equal to operator sign (=) is identical to the assignment operator. We need to be careful.

(Continued on next part...)

Part:   1   2 

Dr. Herong Yang, updated in 2006
VBScript Tutorials - Herong's Tutorial Notes - Comparison and Logic Operations