讓我們假設一個表達式4+5等於9。這裡,4和5稱爲操作數,而+稱爲運算符。VBScript語言支持以下類型的運算符−
- Arithmetic Operators
- Comparison Operators
- Logical (or Relational) Operators
- Concatenation Operators
The Arithmetic Operators
VBScript支持以下算術運算符−
假設變量A爲5,變量B爲10,則-;
Operator | Description | Example |
---|---|---|
+ | Adds two operands | A + B will give 15 |
- | Subtracts second operand from the first | A - B will give -5 |
* | Multiply both operands | A * B will give 50 |
/ | Divide numerator by denumerator | B / A will give 2 |
% | Modulus Operator and remainder of after an integer division | B MOD A will give 0 |
^ | Exponentiation Operator | B ^ A will give 100000 |
要更好地理解這些運算符,您可以自己嘗試。
The Comparison Operators
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. |
要更好地理解這些運算符,您可以自己嘗試。
The Logical Operators
VBScript語言支持以下邏輯運算符−
假設變量A保持10,變量B保持0,然後&負;
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. |
要更好地理解這些運算符,您可以自己嘗試。
The Concatenation Operators
VBScript語言支持以下連接運算符−
假設變量A爲5,變量B爲10,則-;
顯示示例
Operator | Description | Example |
---|---|---|
+ | Adds two Values as Variable Values are Numeric | A + B will give 15 |
& | Concatenates two Values | A & B will give 510 |
假設變量A=「Microsoft」和變量B=「VBScript」,然後−
Operator | Description | Example |
---|---|---|
+ | Concatenates two Values | A + B will give MicrosoftVBScript |
& | Concatenates two Values | A & B will give MicrosoftVBScript |
注意−連接運算符可用於數字和字符串。如果變量包含數值或字符串值,則輸出取決於上下文。
要更好地理解這些運算符,您可以自己嘗試。