VB.Net - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

VB.Net Constants

VB.Net Constants

shape Description

The constant is also a variable, but the value of the constant must be fixed. The constant value is not going to change during its lifetime. Once we define with the one value, that value should apply to the entire program.Simply, we can say that Constant is a Fixed Value. We can also call constant as "literal".The Constant may be any of the following types. The type of the constant value depends on the user requirement.The Constant value should be declared with the keyword called "Const".

shape Conceptual figure

Following is a conceptual figure which describes the root of constants.

shape Syntax

[vbnet][accessmodifier] Const constantname [As datatype]=initializer[/vbnet]

shape Example

[vbnet]public Const a [As integer]=100[/vbnet] See the above example.Here, public is the access specifier, a is the Constant name, integer is the datatype, and the 100 is the initialized value which is going to be fixed. [vbnet] Module ConstantExample Sub Main() Const PI = 3.14149 Dim r, area As integer r = 7 area = PI * r* r Console.WriteLine("Area = " & Str(area)) Console.ReadKey() End Sub End Module [/vbnet] Output: When you execute the above code, then you will get the following output.

Summary

shape Points

  • Enum is a combination of constants.
  • Once developer declare the constants then it can not be changed but it will be used to the whole program.
  • Display and print both are the constants available in VB.Net.