In contrast to variables, constants contain any number of fixed values that you cannot change at program runtime. A corresponding attempt would result in an error message! You must also specify the required data type for the constants in the declaration.
Constants data types can only be Boolean, integer, long, float or string. With the optional keywords Public or Private you can set the access rights to a constant. If you use the keyword Public, the declared constant can also be accessed from the other classes that have a reference to an object of this class. Without public or private, only one class global constant is declared.
Public Const FILE_PATH As String = "/home/hans/files" Const COURSE_NUMBER As Integer = 7 Const FACTOR As Float = 2.222 Private Const DEBUG As Boolean = True
These declarations of constants are incorrect:
(1) Const VALUE As Float = COURSE_NUMBER / FACTOR (2) Const FACTOR3 As Float = 2.71828182845 / 3.1415 (3) Const DATE As Date = "12.12.2012" (4) Const NUMBER_PI As Float = Pi()
An enumeration is a list of integer constants in a list where each constant has its own name and integer value. The individual values in the list are separated by commas. If you do not assign an integer value, the first value in the list is 0 and all subsequent values are increased by 1. The keyword is Enum. You can also define access rights for constants using the keywords Public or Private.
(1) Public Enum Spring, Summer, Autumn, Winter (2) Private Enum top = 5, bottom, left, right (3) Enum LehmannRed = 16711680, MeierYellow = &HFFFF44, BoegeGreen = &H00FF08 (4) (5) Public Sub SetSeason(iSeason As Integer) (6) Select Case iSeason (7) Case Spring (8) Message.Info("Spring lets its blue ribbon ...!") (9) Case Summer (10) Message.Info("Summer, sun, Baltic Sea beach!") (11) Case Autumn (12) Message.Info("When the leaves fall in autumn ...!") (13) Case Else ' Winter (14) Message.Info("Winter at last!") (15) End Select ' iSeason (16) End ' SetSeason(...) (17) (18) Public Sub SetColour(iColour As Integer) (19) TextArea1.Background = iColour (20) End ' SetColour(...) (21) (22) Public Sub btnEnumeration_Click() (23) SetSeason(Winter) (24) SetColour(MeierGelb) (25) Message.Info("The value for left is " & left & ".") (26) End ' btnEnumeration_Click()