Vba-operators
提供:Dev Guides
VBA-オペレーター
演算子*は、単純な式-4+を使用して定義できます。 5は9です。 ここで、4と5は*オペランド*と+と呼ばれます。 *operator と呼ばれます。 VBAは次の種類の演算子をサポートしています-
- 算術演算子
- 比較演算子
- 論理(またはリレーショナル)演算子
- 連結演算子
算術演算子
次の算術演算子はVBAでサポートされています。
変数Aが5を保持し、変数Bが10を保持すると仮定します-
リンク:/vba/vba_arithmetic_operators [例を表示]
Operator | Description | Example |
---|---|---|
PLUS | Adds the two operands | A PLUS B will give 15 |
- | Subtracts the second operand from the first | A - B will give -5 |
AST | Multiplies both the operands | A AST B will give 50 |
/ | Divides the numerator by the denominator | B/A will give 2 |
% | Modulus operator and the remainder after an integer division | B % A will give 0 |
^ | Exponentiation operator | B ^ A will give 100000 |
比較演算子
VBAでサポートされている比較演算子は次のとおりです。
変数Aが10を保持し、変数Bが20を保持すると仮定します-
リンク:/vba/vba_comparison_operators [例を表示]
Operator | Description | Example |
---|---|---|
= | Checks if the value of the two operands are equal or not. If yes, then the condition is true. | (A = B) is False. |
<> | Checks if the value of the two operands are equal or not. If the values are not equal, then the condition is true. | (A <> B) is True. |
> | Checks if the value of the left operand is greater than the value of the right operand. If yes, then the condition is true. | (A > B) is False. |
< | Checks if the value of the left operand is less than the value of the right operand. If yes, then the condition is true. | (A < B) is True. |
>= | Checks if the value of the left operand is greater than or equal to the value of the right operand. If yes, then the condition is true. | (A >= B) is False. |
⇐ | Checks if the value of the left operand is less than or equal to the value of the right operand. If yes, then the condition is true. | (A ⇐ B) is True. |
論理演算子
次の論理演算子はVBAでサポートされています。
変数Aが10を保持し、変数Bが0を保持すると仮定します-
リンク:/vba/vba_logical_operators [例を表示]
Operator | Description | Example |
---|---|---|
AND | Called Logical AND operator. If both the conditions are True, then the Expression is true. | a<>0 AND b<>0 is False. |
OR | Called Logical OR Operator. If any of the two conditions are True, then the condition is true. | a<>0 OR b<>0 is true. |
NOT | Called Logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make 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 be True, the result is True. | (a<>0 XOR b<>0) is true. |
連結演算子
次の連結演算子はVBAでサポートされています。
変数Aが5を保持し、変数Bが10を保持すると仮定します-
link:/vba/vba_concatenation_operators [例を表示]
Operator | Description | Example |
---|---|---|
PLUS | Adds two Values as Variable. Values are Numeric | A PLUS B will give 15 |
& | Concatenates two Values | A & B will give 510 |
変数A = "Microsoft"と変数B = "VBScript"を仮定し、その後-
Operator | Description | Example |
---|---|---|
PLUS | Concatenates two Values | A PLUS B will give MicrosoftVBScript |
& | Concatenates two Values | A & B will give MicrosoftVBScript |
注-連結演算子は、数値と文字列の両方に使用できます。 変数が数値または文字列値を保持する場合、出力はコンテキストに依存します。