VBScript arithmetic operator

From StealthBot Wiki

Jump to: navigation, search

VBScript arithmetic operators allow you to calculate numeric values with the well-known math operators from numeric operands.

Contents

Addition operator: +

Use this to add the two numeric operands together.

Var2 = 1 + 1

Var2 will hold 2.

If either type is a double the result is a double. Otherwise, the result is an integer.

Note that if either operand is a non-number-like string, the + operator will concatenate them.

Subtraction operator: -

Use this to subtract the right operand from the left.

Var1 = 2 - 1

Var1 will hold 1.

If either type is a double the result is a double. Otherwise, the result is an integer.

Negation operator: -

The negation operator normally is seen with a numeric literal, stating that the literal is a negative number. But, the - operator can be placed before any variable or result to get the opposite (* -1) of the value. This is a unary operator, meaning it operates on only one operand on its right. If there are two operands, - becomes the subtraction operator.

Store the value -1, or the opposite of the value 1.

Var1 = -1

Store the opposite of SomeFunction()'s result.

Var1 = -SomeFunction()

The + operator can be used in the same way, however does not have any mathematical effect (* 1).

Multiplication operator: *

Use this to multiply two numeric operands together.

Var10 = 2 * 5

Var10 will hold 10.

If either type is a double the result is a double. Otherwise, the result is an integer.

Division operator: /

Use this to divide the left operand into the right operand.

Var5 = 10 / 2

Var5 will hold 5.

The result is always a double.

Integer division operator: \

Use this to divide the left operand into the right operand.

Var5 = 10 \ 2

Var5 will hold 5.

The result is always an integer. The result will be rounded down.

Var1 = 9 / 5
Var2 = 9 \ 5

Var1 equals 1.8 and Var2 equals 1.

Modulus operator: Mod

This operator will divide the left operand into the right operand and return the remainder of the division.

Var1 = 3 Mod 2

Var1 will hold 1.

If either type is a double the result is a double. Otherwise, the result is an integer.

Exponent operator: ^

Use this to raise the left operand to the power of the right operand.

Var256 = 2 ^ 8

Var256 will hold 256.

The result is always a double.

See also

Personal tools