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

VB.Net Directives

VB.Net Directives

shape Description

The VB.Net Directives, specifies "How the compiler will compile its input". The main Directives are the Compiler Directives in VB.Net.The Compiler Directives always begin with the # symbol. The Directives are not the Statements.The processing starts before the compilation because, VB.Net does not have the Preprocessor.The Directive takes the responsibilities of the preprocessor.Following are the types of directives.

shape Conceptual figure

Following figure will describe about the types of directive.

shape Example

#Const Directive:It is used to define conditions.Following is a basic syntax and an example to describe #Const Directive.
#Const constname = expression
[vbnet]<span class="com">#Const state = "WEST BENGAL"</span>[/vbnet] [vbnet]Module Module1 #Const age = True Sub Main() #If age Then Console.WriteLine("You are welcome to the Robotics Club") #End If Console.ReadKey() End Sub End Module[/vbnet] Output: #ExternalSource Directive:This directive will be utilized by compiler.Following is a syntax and an example.
#ExternalSource( StringLiteral , IntLiteral ) [ LogicalLine ] #End ExternalSource
[vbnet]Module Module1 Public Class ExternalSourceTester Sub TestExternalSource() #ExternalSource("c:\vbprogs\directives.vb", 5) Console.WriteLine("SPlessons brings code for you. ") Console.WriteLine("This is External Code. ") #End ExternalSource End Sub End Class Sub Main() Dim t As New ExternalSourceTester() t.TestExternalSource() Console.WriteLine("In Main.") Console.ReadKey() End Sub End Module[/vbnet] Output: #If...#Then...#Else Directive:This directive describes conditions.Following is a syntax and an example.
#If expression Then statements [ #ElseIf expression Then [ statements ] ... #ElseIf expression Then [ statements ] ] [ #Else [ statements ] ] #End If
[vbnet]Module Module1 #Const classCode = 8 Sub Main() #If classCode = 7 Then Console.WriteLine("SPlesson will bring ideas to life") #ElseIf classCode = 8 Then Console.WriteLine("SPlesson makes code as easy to understand") #Else Console.WriteLine("SPlesson tutorials will guide to bigginers and to experienced persons.") #End If Console.ReadKey() End Sub End Module[/vbnet] Output: #Region Directive:This directive id utilized to hide blocks of the code.Following is a syntax and an example.
#Region "identifier_string" #End Region
[vbnet]Module Module1 #Region "INIT" ''' <summary> ''' Initialize the program. ''' </summary> Sub Main() Console.WriteLine("A") Console.WriteLine("B") Console.WriteLine("C") Console.WriteLine("Copyright 2013") End Sub #End Region End Module[/vbnet]

Summary

shape Points

  • Directives will have the instructions that will be used by the compiler.
  • Directive will begin with '#'.
  • Spaces may  appear before a directive.