Vbscript-comparison-operators

提供:Dev Guides
移動先:案内検索

VBScriptの比較演算子

次の表は、VBScript言語でサポートされているすべての比較演算子を示しています。 変数Aが10を保持し、変数Bが20を保持すると仮定すると:

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.

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>

lとして保存してInternet Explorerで実行すると、上記のスクリプトは次の結果を生成します。

Operator Line 1 : False

Operator Line 2 : True

Operator Line 3 : False

Operator Line 4 : True

Operator Line 5 : False

Operator Line 6 : True