Wednesday, October 27, 2010

Constants

Some applications need to work with known values that do not change. As such, these values may be programmed into a programming entity known as a constant.

Constants are often used to enforce business rules within an application. For instance, a membership fee - 49.95, the number of days it takes to process an order - 7, the amount of damage required to destroy an enemy - 100. When a value is stored in a constant, it cannot be changed during program execution.

A declaration statement is used to declare the existence of the constant. It is defined as a particular data type. It may then be assigned a value.

Syntax
Const ConstantName As DataType

Code eg: Declaring a constant.
In this case, the constant is an Integer data type called intDamage with a value of 100.
    Const intDamageRequired As Integer = 100

No comments:

Post a Comment