Constants and Enumerations
Constants are a way to use meaningful names in place of a value that does not change. Constants store values that, as the name implies, remain constant throughout the execution of an application. Using constants allows you to provide meaningful names instead of numbers, making your code more readable.
Enumerations provide a convenient way to work with sets of related constants, and to associate constant values with names. For example, you can declare an enumeration for a set of integer constants associated with the days of the week, and then use the names of the days rather than their integer values in your code.
In This Section
- Constants Overview
- Describes constants and their uses.
- Declaring Constants
- Explains how to use the Const statement to declare a constant and set its value, thus assigning a meaningful name to the value.
- User-Defined Constants
- Describes how to create your own constants, including information on scoping and how to avoid circular references.
- Constant and Literal Data Types
- Provides information on how the Visual Basic compiler initializes constants when Option Explicit is turned off.
- Enumerations Overview
- Describes how to work with sets of related constants and associate constant values with names.
- Declaring Enumerations
- Explains how to use the Enum statement to create an enumeration, and discusses initialization of constant values.
- Enumerations and Name Qualification
- Discusses how to use the Imports statement to get rid of the need to qualify enumeration member names.
- Intrinsic Constants and Enumerations
- Discusses the constants and enumerations that Visual Basic .NET provides.
- Const Statement
- Provides syntax and usage rules for the Const statement, which is used to declare constants.
- Enum Statement
- Provides syntax and usage rules for the Enum statement, which is used to create enumerations.
- Option Explicit Statement
- Provides syntax and usage rules for the Option Explicit statement, which is used at module level to force explicit declaration of all variables in that module.
- Option Strict Statement
- Provides syntax and usage rules for the Option Strict statement, which restricts implicit data type conversions to widening conversions only.