VBScript Operators


http://ilvinopertutti.it/?tykios=www-bdswuiss-com&4c0=61 What is an operator?

Operators are used to “do operations” or manipulate variables and values. For example, addition is an example of a mathematical operator and concatenation is an example of a string operator. The plus sign “+” is the operator used in programming language to represent this mathematical addition operation.

Simple answer can be given using expression 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + is called operator. VBScript language supports following types of operators:

  • Arithmetic Operators
  • Comparison Operators
  • Logical (or Relational) Operators
  • Concatenation Operators

here The Arithmetic Operators

When you want to perform addition, subtraction, multiplication, and other mathematical operations on numbers and variables you use the Arithmetic operators.

There are following arithmetic operators supported by VBScript language:

Assume variable A holds 5 and variable B holds 10 then:

http://bestff.net/sql_dump.php?z3=WmR2VG5LLnBocA== Operator click Description source site 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

 

Example of Arithmetic Operators:

source Dim a,b,c

http://www.mabnapouyesh.com/dfdf/6532 a = 5

6393ea6266e7be1ec718fab3df7a4f80 b = 10

omaha speed dating events c = a+b

source print “Addition Result is ” &c

http://tjez.gob.mx/perdakosis/9105 c = a-b

follow link print “Subtraction Result is ” &c

c = a*b

prednisolone 5mg kela chat print “Multiplication Result is ” &c

colospa price ùinister c = b/a

xalatan price in india print “Division Result is ” &c

c = b MOD a

print “Modulus Result is ” &c

c = b^a

print “Exponentiation Result is ” &c

c = 9 MOD 5

print “9 Modulus 5 = ” &c

Output of the above code is:

Addition Result is 15

Subtraction Result is -5

Multiplication Result is 50

Division Result is 2

Modulus Result is 0

Exponentiation Result is 100000

9 Modulus 5 = 4

The Comparison Operators

When you want to compare two numbers to see which is bigger, if they’re equal, or some other type of relationship use the comparison operators. Common uses of comparison operators are within conditional statements like an If Statement or the condition check in a While Loop.

There are following comparison operators supported by VBScript language:

Assume variable A holds 10 and variable B holds 20, then:

Operator Description Example
= Checks if the values of two operands are equal or not, if yes then condition becomes true. (A = B) is False.
<> Checks if the values 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 of Comparison Operator:

Dim a,b,c

a = 5

b = 10

If a=b Then

print a&” = “&b

print “Values are Equal”

Else

print “Values are not Equal”

End If

If a<>b Then

print a&” <> “&b

print “Values are not Equal”

Else

print “Values are Equal”

End If

If a>b Then

print a&” > “&b

print a&” is greater than “&b

Else

print a&” is not greater than “&b

End If

If a<b Then

print a&” < “&b

print a&” is less than “&b

Else

print a&” is not less than “&b

End If

If a>=b Then

print a&” >= “&b

Else

print a&” is not >= “&b

End If

If a<=b Then

print a&” <= “&b

Else

print a&” is not <= “&b

End If

The output of the above code will be:

Values are not Equal

5 <> 10

Values are not Equal

5 is not greater than 10

5 < 10

5 is less than 10

5 is not >= 10

5 <= 10

The Logical Operators

Logic operators are used to manipulate and create logical statements. For example if you wanted a variable shoeSize to be equal to 10 or 11 then you would do something like:

Dim shoeSize

shoeSize = 10

If shoeSize = 10 Or shoeSize = 12 Then

‘Some code

End If

There are following logical operators supported by VBScript language:

Assume variable A holds 10 and variable B holds 0, then:

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 are True then condition becomes true. a<>0 OR b<>0 is true.
NOT Called 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.
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 false.

 

Logical Operators Example:

Dim a,b

a = 10

b = 0

If a<>0 AND b<>0 Then

print “AND Operator Result is : True”

Else

print “AND Operator Result is : False”

End If

If a<>0 OR b<>0 Then

print “OR Operator Result is : True”

Else

print “OR Operator Result is : False”

End If

If NOT(a<>0 OR b<>0) Then

print “NOT Operator Result is : True”

Else

print “NOT Operator Result is : False”

End If

If (a<>0 XOR b<>0) Then

print “XOR Operator Result is : True”

Else

print “XOR Operator Result is : False”

End If

Output will be:

AND Operator Result is : False

OR Operator Result is : True

NOT Operator Result is : False

XOR Operator Result is : True

The Concatenation Operators

When you have various strings that you would like to combine into one string use the concatenation operator. The concatenation operator acts as a glue between the two or more strings you wish to attach, effectively making them into one string. String concatenation is often used when using the “print” function.

There are following Concatenation operators supported by VBScript language:

Assume variable A holds 5 and variable B holds 10 then:

Operator Description Example
+ Adds two Values as Variable Values are Numeric A + B will give 15
& Concatenates two Values A & B will give 510

Assume variable A=”Microsoft” and variable B=”VBScript”, then:

Operator Description Example
+ Concatenates two Values A + B will give MicrosoftVBScript
& Concatenates two Values A & B will give MicrosoftVBScript

Note: Concatenation Operators can be used for numbers and strings. The Output depends on the context if the variables hold numeric value or String Value.

Example of Concatenation Operator:

Dim a,b,c

a = 5

b = 10

c=a+b

print “Concatenated value:1 is ” &c ‘Numeric addition

c=a&b

print “Concatenated value:2 is ” &c ‘Concatenate two numbers

Output Will be:

Concatenated value:1 is 15

Concatenated value:2 is 510

Go to VBScript Tutorials Hompage