Menu

VB.NET TUTORIALS - VB.Net - Constants

VB.Net - Constants

ADVERTISEMENTS

Print and Display Constants in VB.Net

ConstantDescription
vbCrLfCarriage return/linefeed character combination.
vbCrCarriage return character.
vbLfLinefeed character.
vbNewLineNewline character.
vbNullCharNull character.
vbNullStringNot the same as a zero-length string (""); used for calling external procedures.
vbObjectErrorError number. User-defined error numbers should be greater than this value. For example:
Err.Raise(Number) = vbObjectError + 1000
vbTabTab character.
vbBackBackspace character.

ADVERTISEMENTS

Declaring Constants

[  ] [ accessmodifier ] [ Shadows ] 
Const constantlist

ADVERTISEMENTS

constantname [ As datatype ] = initializer

' The following statements declare constants.  
Const maxval As Long = 4999
Public Const message As String = "HELLO" 
Private Const piValue As Double = 3.1415

Example

Module constantsNenum
   Sub Main()
      Const PI = 3.14149
      Dim radius, area As Single
      radius = 7
      area = PI * radius * radius
      Console.WriteLine("Area = " & Str(area))
      Console.ReadKey()
   End Sub
End Module

Declaring Enumerations

[  ] [ accessmodifier ]  [ Shadows ] 
Enum enumerationname [ As datatype ] 
   memberlist
End Enum

[] member name [ = initializer ]

Enum Colors
   red = 1
   orange = 2
   yellow = 3
   green = 4
   azure = 5
   blue = 6
   violet = 7
End Enum

Example

Module constantsNenum
   Enum Colors
      red = 1
      orange = 2
      yellow = 3
      green = 4
      azure = 5
      blue = 6
      violet = 7
   End Enum
   Sub Main()
      Console.WriteLine("The Color Red is : " & Colors.red)
      Console.WriteLine("The Color Yellow is : " & Colors.yellow)
      Console.WriteLine("The Color Blue is : " & Colors.blue)
      Console.WriteLine("The Color Green is : " & Colors.green)
      Console.ReadKey()
   End Sub
End Module