eWebProgrammer
prev next prev next
  Course navigation
 
Lesson 5
Objective
ASP Arithmetic Operators
Create formulas and test constants and variables.
    Mathematical Operators
Sooner or later, in a Web application, you will need to perform mathematical calculations. In a previous lesson, we used the multiplication (*) and subtraction (-) operations to perform a discount. Here are other mathematical operators available for use in ASP code:
+
Addition 1 + 2 = 3        
-              
Subtraction 2 - 1 = 1 
*              
Multiplication 6 * 3 = 18
/              
Division 6 / 3 = 2
\
Integer Division 6.3 \ 3.1 = 2
Mod
Modulus 8 Mod 3 = 2 (Any remainder is discarded)
^
Exponentiation 8 ^ 2 = 64
(NOTE: This type of division rounds the two numbers to integer values then produces an integer result. Any remaining decimal values are discarded.)
Logical -Boolean-operators
There are also a number of logical operators available for our use.

Two of the most commonly used are
  1. NOT and
  2. AND.
If Not  (A = 5) Then . . .
  'If A is NOT equal to 5,
  'then something happens
  'Can also be written as A <> 5
	.
	.
If (A <> 5) AND (A <> 7) Then . . .
  'If A is not equal to 5 AND 
  'A is not equal to 7 
  'then something happens
            .
The next lesson presents some common programming structures used in ASP scripts.
ASP Operators Quiz
Click the Quiz link below to check your understanding of the topics discussed in the last few lessons.
ASP Operators Quiz
  Course navigation