Use the right type for constants

Use the right type for constants

VB stores symbolic and literal constants internally using the simplest data type possible; this means that most common numeric constants-such as zero or one-are stored as Integers. If you use these constants in floating point expressions you can speed up your code using a constant of appropriate type, as in:

value# = value# + 1#.

This forces the compiler to store the constant in Double format, thus saving one implicit conversion at runtime. Alternatively, you can declare and use a symbolic constant of a well defined type, as in:

Const ONE As Double = 1


Share the Post: