More About Constants

There are different kinds of Constants.

 

Numeric constants look like

787.5                  .00983                       -25


Numeric constants are stored in memory in the most efficient manner determined by the size of the number. You can explicitly state the date type by adding a letter on the end of the number to indicate the way you wish the numeric constant to be stored.

Numeric constants may be used in calculations

 


Literal Constant

Anything enclosed in quotation marks is considered a literal constant and is treated as nonnumeric

“Hello”                 “Parkland College”                   “123,233.56”

 


Named Constants / User-Defined Constants


You can create your own Constants using the keyword Const.

 Const SALES_TAX_RATE As Single = .0725


Named constants may look like variables but their value cannot be changed in code. A value must be assigned to them when they are declared and it cannot be changed elsewhere. When ever we reference the named constant in code we are using the value assigned to it. We use named constants for constant values in our programs to provide descriptive names for values and to make changing those values in the future easier. A named constant should be named so that it is easily recognized as a Named Constant.

sngTax = sngTotalPurchaseAmt * SALES_TAX_RATE


Named constants are typically declared at the module level to make them available through-out the module.