Friday 10 March 2017

Operators in VB Script

Operators

VB Script has a full range of operators, including arithmetic operator, comparison operator, concatenation operators, and logical operators.

The Arithmetic Operators


OperatorDescriptionExample
+Adds two operandsA + B will give 15
-Subtracts second operand from the firstA - B will give -5
*Multiply both operandsA * B will give 50
/Divide numerator by denumeratorB / A will give 2
%Modulus Operator and remainder of after an integer divisionB MOD A will give 0
^Exponentiation OperatorB ^ A will give 100000

The Comparison Operators

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.

The Logical Operators

OperatorDescriptionExample
ANDCalled Logical AND operator. If both the conditions are True then Expression becomes true.a<>0 AND b<>0 is False.
ORCalled Logical OR Operator. If any of the two conditions are True then condition becomes true.a<>0 OR b<>0 is true.
NOTCalled Logical NOT Operator. Use to reverses 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.
XORCalled 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 false.

The Concatenation Operators

OperatorDescriptionExample
+Adds two Values as Variable Values are NumericA + B will give 15
&Concatenates two ValuesA & B will give 510
Assume variable A="Microsoft" and variable B="VBScript", then:
OperatorDescriptionExample
+Concatenates two ValuesA + B will give MicrosoftVBScript
&Concatenates two ValuesA & B will give MicrosoftVBScript

No comments:

Post a Comment