Comparison Operators in VBScript

Advertisements


Following table shows all the Comparison operators supported by VBScript language. Assume variable A holds 10 and variable B holds 20, then:

OperatorDescriptionExample
== 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


Advertisements
Advertisements