Suite101

Operators in VBScript. Arithmetic Operators


© Maxim Karetnikov
Page 2
Result=-Number 

Multiplication

In most computer languages, the * symbol is used to indicate multiplication, not the x symbol. You might be able to use x on paper, but to the computer, x is a variable, not a multiplication symbol. The application rules are the same as for above arithmetic operators, e.g.,

Result = Number1 * 2 * Number1 * 3 * Number1 

Division

The division operator is the last of the four commonly used arithmetic operators. Among the common arithmetic operators, division is the most complicated arithmetic operation a computer performs. The syntax for division is the same as any of the other operators. VBScript has two types of division operators. The first operator handles numbers with decimal points. Usually referred to as the floating-point division operator, it's represented by the / symbol in code listings.

c = a / b

So, if a=5 and b=4, it returns 1.25.

To perform a division without a decimal point in the result, e.g., to round the results, you can use the integer division operator.

c = a \ b

It drops the decimal point off. If a=5 and b=4, it gives 1 (rounded 1.25).

The complexity of division operator is due to the run-error occurred in case of dividing by zero. For example, the statement

2 / 0

results in an error in VBScript. Most people know that it is impossible to divide by zero in the system of real numbers, and most programmers would never intentionally design code that divides by zero. However, they often simply fail to prevent it from happening or overlook cases where it could occur.

Modulo Operator

The Mod, or modulo arithmetic, operator allows you to determine the remainder when one number is divided by another number. The operator uses integer division to divide one value by the other; once an integer value is determined, the value that remains is what the Mod operator returns. If the number divides into the other number without remainder, it returns 0. But if, for example, you divide 3 into 10, you would have a remainder of 1.

Go To Page: 1 2


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo