Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
12. Visual Basic .NET Grammar Summary

12. Visual Basic .NET Grammar Summary

Visual Studio .NET 2003

This section summarizes the Visual Basic language grammar. For information on how to read the grammar, see 1.1 Grammar Notation.

2. Lexical Grammar

Start ::= [ LogicalLine+ ]
LogicalLine ::= [ LogicalLineElement+ ] [ Comment ] LineTerminator
LogicalLineElement ::= WhiteSpace | LineContinuation | Token
Token ::= Identifier | Keyword | Literal | Separator | Operator

2.1 Characters and Lines

Character ::= < any Unicode character except a LineTerminator >

2.1.1 Line Terminators

LineTerminator ::=
   < Unicode carriage return character (0x000D) > |
   < Unicode linefeed character (0x000A) > |
   < Unicode carriage return character > < Unicode linefeed character > |
   < Unicode line separator character (0x2028) > |
   < Unicode paragraph separator character (0x2029) >

2.1.2 Line Continuation

LineContinuation ::= WhiteSpace _ [ WhiteSpace+ ] LineTerminator

2.1.3 White Space

WhiteSpace ::=
   < Unicode blank characters (class Zs) > |
   < Unicode tab character (0x0009) >

2.1.4 Comments

Comment ::= CommentMarker [ Character+ ]
CommentMarker ::= SingleQuoteCharacter | REM
SingleQuoteCharacter ::=
   ' |
   < Unicode left single-quote character (0x2018) |
   < Unicode right single-quote character (0x2019)

2.2 Identifiers

Identifier ::=
   NonEscapedIdentifier [ TypeCharacter ] |
   EscapedIdentifier
NonEscapedIdentifier ::= < IdentifierName but not Keyword >
EscapedIdentifier ::= [ IdentifierName ] 
IdentifierName ::= IdentifierStart [ IdentifierCharacter+ ]
IdentifierStart ::=
   AlphaCharacter |
   UnderscoreCharacter IdentifierCharacter
IdentifierCharacter ::=
   UnderscoreCharacter |
   AlphaCharacter |
   NumericCharacter |
   CombiningCharacter |
   FormattingCharacter
AlphaCharacter ::=
   < Unicode alphabetic character (classes Lu, Ll, Lt, Lm, Lo, Nl) >
NumericCharacter ::= < Unicode decimal digit character (class Nd) >
CombiningCharacter ::= < Unicode combining character (classes Mn, Mc) >
FormattingCharacter ::= < Unicode formatting character (class Cf) >
UnderscoreCharacter ::= < Unicode connection character (class Pc) >
IdentifierOrKeyword ::= Identifier | Keyword

2.2.1 Type Characters

TypeCharacter ::=
   IntegerTypeCharacter |
   LongTypeCharacter |
   DecimalTypeCharacter |
   SingleTypeCharacter |
   DoubleTypeCharacter |
   StringTypeCharacter
IntegerTypeCharacter ::= %
LongTypeCharacter ::= &
DecimalTypeCharacter ::= @
SingleTypeCharacter ::= !
DoubleTypeCharacter ::= #
StringTypeCharacter ::= $

2.3 Keywords

Keyword ::= < member of keyword table at 2.3 Keywords >

2.4 Literals

Literal ::= 
   BooleanLiteral | 
   IntegerLiteral | 
   FloatingPointLiteral | 
   StringLiteral | 
   CharacterLiteral | 
   DateLiteral | 
   Nothing

2.4.1 Boolean Literals

BooleanLiteral ::= True | False

2.4.2 Integer Literals

IntegerLiteral ::= IntegralLiteralValue [ IntegralTypeCharacter ]
IntegralLiteralValue ::= IntLiteral | HexLiteral | OctalLiteral 
IntegralTypeCharacter ::=
   ShortCharacter |
   IntegerCharacter |
   LongCharacter |
   IntegerTypeCharacter |
   LongTypeCharacter
ShortCharacter ::= S
IntegerCharacter ::= I
LongCharacter ::= L
IntLiteral ::= Digit+
HexLiteral ::= & H HexDigit+
OctalLiteral ::= & O OctalDigit+
Digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
HexDigit ::=
   0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F
OctalDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 

2.4.3 Floating-Point Literals

FloatingPointLiteral ::=
   FloatingPointLiteralValue [ FloatingPointTypeCharacter ] |
   IntLiteral FloatingPointTypeCharacter
FloatingPointTypeCharacter ::=
   SingleCharacter |
   DoubleCharacter |
   DecimalCharacter |
   SingleTypeCharacter |
   DoubleTypeCharacter |
   DecimalTypeCharacter
SingleCharacter ::= F
DoubleCharacter ::= R
DecimalCharacter ::= D 
FloatingPointLiteralValue ::=
   IntLiteral . IntLiteral [ Exponent ] |
   . IntLiteral [ Exponent ] |
   IntLiteral Exponent
Exponent ::= E [ Sign ] IntLiteral
Sign ::= + | -

2.4.4 String Literals

StringLiteral ::=
   DoubleQuoteCharacter [ StringCharacter+ ] DoubleQuoteCharacter
DoubleQuoteCharacter ::=
   " |
   < Unicode left double-quote character (0x201C) > |
   < Unicode right double-quote character (0x201D) >
StringCharacter ::= 
   < Character except for DoubleQuoteCharacter > |
   DoubleQuoteCharacter DoubleQuoteCharacter

2.4.5 Character Literals

CharacterLiteral ::=
   DoubleQuoteCharacter StringCharacter DoubleQuoteCharacter C

2.4.6 Date Literals

DateLiteral ::= # [ Whitespace+ ] DateOrTime [ Whitespace+ ] #
DateOrTime ::=
   DateValue Whitespace+ TimeValue |
   DateValue |
   TimeValue
DateValue ::=
   MonthValue / DayValue / YearValue |
   MonthValue – DayValue - YearValue
TimeValue ::=
   HourValue : MinuteValue [ : SecondValue ] [ WhiteSpace+ ] [ AMPM ]
MonthValue ::= IntLiteral
DayValue ::= IntLiteral
YearValue ::= IntLiteral
HourValue ::= IntLiteral
MinuteValue ::= IntLiteral
SecondValue ::= IntLiteral
AMPM ::= AM | PM

2.4.7 Nothing

Nothing ::= Nothing

2.5 Separators

Separator ::= ( | ) | { | } | ! | # | , | . | :

2.6 Operator Characters

Operator ::= & | * | + | - | / | \ | ^ | < | = | >

3. Preprocessing Directives

3.1 Conditional Compilation

Start ::= [ ConditionalElement+ ]
ConditionalElement ::= 
   ConditionalConstantDeclaration | 
   ConditionalIfGroup | 
   LogicalLine

3.1.1 Conditional Constant Directives

ConditionalConstantDeclaration ::=
   # Const Identifier = ConstantExpression LineTerminator

3.1.2 Conditional Compilation Directives

ConditionalIfGroup ::=
   # If ConstantExpression [ Then ] LineTerminator
   [ ConditionalElement+ ] 
   [ ConditionalElseIfGroup+ ] 
   [ ConditionalElseGroup ] 
   # End If LineTerminator
ConditionalElseIfGroup ::=
   # ElseIf ConstantExpression [ Then ] LineTerminator
   [ ConditionalElement+ ]
ConditionalElseGroup ::= 
   # Else LineTerminator
   [ ConditionalElement+ ]

3.2 External Source Directives

Start ::= [ ExternalSourceElement+ ]
ExternalSourceElement ::= ExternalSourceGroup | LogicalLine
ExternalSourceGroup ::=
   # ExternalSource ( StringLiteral , IntLiteral ) LineTerminator
   [ LogicalLine+ ]
   # End ExternalSource LineTerminator

3.3 Region Directives

Start ::= [ RegionElement+ ]
RegionElement ::= RegionGroup | LogicalLine
RegionGroup ::=
   # Region StringLiteral LineTerminator
   [ LogicalLine+ ]
   # End Region LineTerminator

4. General Concepts

4.6 Accessibility

AccessModifier ::= Public | Protected | Friend | Private

4.7 Type and Namespace Names

QualifiedIdentifier ::=
   Identifier |
   QualifiedIdentifier . IdentifierOrKeyword
NamespaceOrTypeName ::= QualifiedIdentifier

5. Attributes

5.2 Attribute Blocks

Attributes ::= < AttributeList >
AttributeList ::=
   Attribute |
   AttributeList , Attribute
Attribute ::=
   [ AttributeModifier : ] TypeName [ ( [ AttributeArguments ] ) ]
AttributeModifier ::= Assembly | Module

5.2.2 Attribute Arguments

AttributeArguments ::=
   AttributePositionalArgumentList |
   AttributePositionalArgumentList , VariablePropertyInitializerList |
   VariablePropertyInitializerList
AttributePositionalArgumentList ::=
   ConstantExpression |
   AttributePositionalArgumentList , ConstantExpression
VariablePropertyInitializerList ::=
   VariablePropertyInitializer |
   VariablePropertyInitializerList , VariablePropertyInitializer
VariablePropertyInitializer ::=
   IdentifierOrKeyword : = ConstantExpression

6. Source Files and Namespaces

Start ::=
   [ OptionStatement+ ]
   [ ImportsStatement+ ]
   [ Attributes ]
   [ NamespaceMemberDeclaration+ ]

6.2 Compilation Options

OptionStatement ::=
   OptionExplicitStatement | 
   OptionStrictStatement | 
   OptionCompareStatement

6.2.1 Option Explicit Statement

OptionExplicitStatement ::= Option Explicit [ OnOff ] LineTerminator
OnOff ::= On | Off

6.2.2 Option Strict Statement

OptionStrictStatement ::= Option Strict [ OnOff ] LineTerminator

6.2.3 Option Compare Statement

OptionCompareStatement ::= Option Compare CompareOption LineTerminator
CompareOption ::= Binary | Text

6.3 Imports Statement

ImportsStatement ::= Imports ImportsClauses LineTerminator
ImportsClauses ::=
   ImportsClause |
   ImportsClauses , ImportsClause
ImportsClause ::= ImportsAliasClause | ImportsNamespaceClause

6.3.1 Import Aliases

ImportsAliasClause ::= Identifier = NamespaceOrTypeName

6.3.2 Namespace Imports

ImportsNamespaceClause ::= NamespaceOrTypeName

6.4.1 Namespace Declarations

NamespaceDeclaration ::=
   Namespace QualifiedIdentifier LineTerminator
   [ NamespaceMemberDeclaration+ ]
   End Namespace LineTerminator

6.4.2 Namespace Members

NamespaceMemberDeclaration ::=
   NamespaceDeclaration |
   TypeDeclaration
TypeDeclaration ::=
   ModuleDeclaration |
   NonModuleDeclaration
NonModuleDeclaration ::=
   EnumDeclaration |
   StructureDeclaration |
   InterfaceDeclaration |
   ClassDeclaration |
   DelegateDeclaration

7. Types

TypeName ::=
   NamespaceOrTypeName |
   BuiltInTypeName |
   ArrayTypeName
BuiltInTypeName ::= Object | PrimitiveTypeName

7.2 Interface Implementation

TypeImplementsClause ::= Implements Implements LineTerminator
Implements ::=
   TypeName |
   Implements , TypeName

7.3 Primitive Types

PrimitiveTypeName ::= NumericTypeName | Boolean | Date | Char | String
NumericTypeName ::= IntegralTypeName | FloatingPointTypeName | Decimal
IntegralTypeName ::= Byte | Short | Integer | Long
FloatingPointTypeName ::= Single | Double

7.4 Enumerations

EnumDeclaration ::=
   [ Attributes ] [ EnumModifier+ ] Enum Identifier
      [ As IntegralTypeName ] LineTerminator
   EnumMemberDeclaration+
   End Enum LineTerminator
EnumModifier ::= AccessModifier | Shadows

7.4.1 Enumeration Members

EnumMemberDeclaration ::=
   [ Attributes ] Identifier [ = ConstantExpression ] LineTerminator

7.5 Classes

ClassDeclaration ::=
   [ Attributes ] [ ClassModifier+ ] Class Identifier LineTerminator
   [ ClassBase ]
   [ TypeImplementsClause+ ]
   [ ClassMemberDeclaration+ ]
   End Class LineTerminator
ClassModifier ::= AccessModifier | Shadows | MustInherit | NotInheritable

7.5.1 Class Base Specification

ClassBase ::= Inherits TypeName LineTerminator

7.5.2 Class Members

ClassMemberDeclaration ::=
   NonModuleDeclaration |
   EventMemberDeclaration |
   VariableMemberDeclaration |
   ConstantMemberDeclaration |
   MethodMemberDeclaration |
   PropertyMemberDeclaration |
   ConstructorMemberDeclaration

7.6 Structures

StructureDeclaration ::=
   [ Attributes ] [ StructureModifier+ ] Structure Identifier
      LineTerminator
   [ TypeImplementsClause+ ]
   [ StructMemberDeclaration+ ]
   End Structure LineTerminator
StructureModifier ::= AccessModifier | Shadows

7.6.1 Structure Members

StructMemberDeclaration ::=
   NonModuleDeclaration | 
   VariableMemberDeclaration |
   ConstantMemberDeclaration |
   EventMemberDeclaration |
   MethodMemberDeclaration |
   PropertyMemberDeclaration |
   ConstructorMemberDeclaration

7.7 Standard Modules

ModuleDeclaration ::=
   [ Attributes ] [ AccessModifier+ ] Module Identifier LineTerminator
   [ ModuleMemberDeclaration+ ]
   End Module LineTerminator

7.7.1 Standard Module Members

ModuleMemberDeclaration ::=
   NonModuleDeclaration |
   VariableMemberDeclaration |
   ConstantMemberDeclaration |
   EventMemberDeclaration |
   MethodMemberDeclaration |
   PropertyMemberDeclaration |
   ConstructorMemberDeclaration

7.8 Interfaces

InterfaceDeclaration ::=
   [ Attributes ] [ InterfaceModifier+ ] Interface Identifier
      LineTerminator
   [ InterfaceBase+ ]
   [ InterfaceMemberDeclaration+ ]
   End Interface LineTerminator
InterfaceModifier ::= AccessModifier | Shadows

7.8.1 Interface Inheritance

InterfaceBase ::= Inherits InterfaceBases LineTerminator
InterfaceBases ::=
   TypeName |
   InterfaceBases , TypeName

7.8.2 Interface Members

InterfaceMemberDeclaration ::=
   NonModuleDeclaration |
   EventMemberDeclaration |
   MethodMemberDeclaration |
   PropertyMemberDeclaration

7.9 Arrays

ArrayTypeName ::= TypeName ArrayTypeModifiers
ArrayTypeModifiers ::= ArrayTypeModifier+
ArrayTypeModifier ::= ( [ RankList ] )
RankList ::=
   , |
   RankList ,
ArrayNameModifier ::=
   ArrayTypeModifiers | 
   ArraySizeInitializationModifier

7.10 Delegates

DelegateDeclaration ::=
   [ Attributes ] [ DelegateModifier+ ] Delegate MethodDeclaration
DelegateModifier ::= AccessModifier | Shadows

9. Type Members

9.1 Interface Method Implementation

ImplementsClause ::= [ Implements ImplementsList ]
ImplementsList ::=
   InterfaceMemberSpecifier |
   ImplementsList , InterfaceMemberSpecifier
InterfaceMemberSpecifier ::= TypeName . Identifier

9.2 Methods

MethodMemberDeclaration ::= MethodDeclaration | ExternalMethodDeclaration

9.2.1 Regular Method Declarations

MethodDeclaration ::= SubDeclaration | FunctionDeclaration
SubDeclaration ::=
   [ Attributes ] [ ProcedureModifier+ ] Sub Identifier
      [ ( [ ParameterList ] ) ] [ HandlesOrImplements ] LineTerminator
   [ Block ]
   [ End Sub LineTerminator ]
FunctionDeclaration ::=
   [ Attributes ] [ ProcedureModifier+ ] Function Identifier
      [ ( [ ParameterList ] ) ] [ As [ Attributes ] TypeName ]
      [ HandlesOrImplements ] LineTerminator
   [ Block ]
   [ End Function LineTerminator ]
ProcedureModifier ::=
   AccessModifier |
   Shadows |
   Shared |
   Overridable |
   NotOverridable |
   MustOverride |
   Overrides |
   Overloads
HandlesOrImplements ::= HandlesClause | ImplementsClause

9.2.2 External Method Declarations

ExternalMethodDeclaration ::=
   ExternalSubDeclaration |
   ExternalFunctionDeclaration
ExternalSubDeclaration ::=
   [ Attributes ] [ ExternalMethodModifier+ ] Declare
      [ CharsetModifier ] Sub Identifier LibraryClause 
      [ AliasClause ] [ ( [ ParameterList ] ) ] LineTerminator
ExternalFunctionDeclaration ::=
   [ Attributes ] [ ExternalMethodModifier+ ] Declare
      [ CharsetModifier ] Function Identifier LibraryClause 
      [ AliasClause ] [ ( [ ParameterList ] ) ] 
      [ As [ Attributes ] TypeName ] LineTerminator
ExternalMethodModifier ::= AccessModifier | Shadows | Overloads
CharsetModifier ::= Ansi | Unicode | Auto
LibraryClause ::= Lib StringLiteral
AliasClause ::= Alias StringLiteral

9.2.5 Method Parameters

ParameterList ::=
   Parameter |
   ParameterList , Parameter
Parameter ::=
   [ Attributes ] ParameterModifier+ Identifier [ As TypeName ]
      [ = ConstantExpression ] 
ParameterModifier ::= ByVal | ByRef | Optional | ParamArray

9.2.6 Event Handling

HandlesClause ::= [ Handles EventHandlesList ]
EventHandlesList ::=
   EventMemberSpecifier |
   EventHandlesList , EventMemberSpecifier
EventMemberSpecifier ::=
   Identifier . Identifier
   MyBase . Identifier

9.3 Constructors

ConstructorMemberDeclaration ::=
   [ Attributes ] [ ConstructorModifier+ ] Sub New
      [ ( [ ParameterList ] ) ] LineTerminator
   [ Block ]
   End Sub LineTerminator
ConstructorModifier ::= AccessModifier | Shared

9.4 Events

EventMemberDeclaration ::=
   [ Attributes ] [ EventModifiers+ ] Event Identifier ParametersOrType
      [ ImplementsClause ] LineTerminator
ParametersOrType ::=
   [ ( [ ParameterList ] ) ] |
   As TypeName
EventModifiers ::= AccessModifier | Shadows | Shared

9.5 Constants

ConstantMemberDeclaration ::=
   [ Attributes ] [ ConstantModifier+ ] Const
      ConstantDeclarators LineTerminator
ConstantModifier ::= AccessModifier | Shadows
ConstantDeclarators ::= 
   ConstantDeclarator |
   ConstantDeclarators , ConstantDeclarator
ConstantDeclarator ::= Identifier [ As TypeName ] =
   ConstantExpression LineTerminator

9.6 Instance and Shared Variables

VariableMemberDeclaration ::=
   [ Attributes ] [ VariableModifier+ ] [ Dim ] VariableDeclarators
      LineTerminator
VariableModifier ::=
   AccessModifier |
   Shadows |
   Shared |
   ReadOnly |
   WithEvents
VariableDeclarators ::=
   VariableDeclarator |
   VariableDeclarators , VariableDeclarator
VariableDeclarator ::=
   VariableIdentifiers [ As TypeName ] |
   VariableIdentifier [ As [ New ] TypeName [ ( ArgumentList ) ] ]
      [ = VariableInitializer ]
VariableIdentifiers ::=
   VariableIdentifier |
   VariableIdentifiers , VariableIdentifier
VariableIdentifier ::= Identifier [ ArrayNameModifier ]

9.6.3 Variable Initializers

VariableInitializer ::= RegularInitializer | ArrayElementInitializer

9.6.3.1 Regular Initializers

RegularInitializer ::= Expression

9.6.3.3 Array-Size Initializers

ArraySizeInitializationModifier ::=
   ( UpperBoundList ) [ ArrayTypeModifiers ]
UpperBoundList::=
   Expression |
   UpperBoundList , Expression

9.6.3.4 Array-Element Initializers

ArrayElementInitializer ::= { [ VariableInitializerList ] }
VariableInitializerList ::=
   VariableInitializer |
   VariableInitializerList , VariableInitializer
VariableInitializer ::= Expression | ArrayElementInitializer

9.7 Properties

PropertyMemberDeclaration ::=
   [ Attributes ] [ PropertyModifier+ ] Property Identifier
      [ ( [ ParameterList ] ) ] [ As TypeName ] [ ImplementsClause ]
      LineTerminator
   [ PropertyAccessorDeclaration+ ]
   [ End Property LineTerminator ]
PropertyModifier ::= ProcedureModifier | Default | ReadOnly | WriteOnly
PropertyAccessorDeclaration ::=
   PropertyGetDeclaration | 
   PropertySetDeclaration

9.7.1 Get Accessor Declarations

PropertyGetDeclaration ::=
   [ Attributes ] Get LineTerminator
   [ Block ]
   End Get

9.7.2 Set Accessor Declarations

PropertySetDeclaration ::=
   [ Attributes ] Set [ ( ParameterList ) ] LineTerminator
   [ Block ]
   End Set

10. Statements

Statement ::=
   LocalDeclarationStatement |
   WithStatement |
   SyncLockStatement |
   EventStatement |
   AssignmentStatement |
   InvocationStatement |
   ConditionalStatement |
   LoopStatement |
   ErrorHandlingStatement |
   BranchStatement |
   ArrayHandlingStatement
StatementTerminator ::= LineTerminator | :

10.1 Blocks

Block ::= [ LabeledLine+ ]
LabeledLine ::= [ LabelName : ] [ Statements ] LineTerminator
LabelName ::= Identifier | IntLiteral
Statements ::=
   [ Statement ] |
   Statements : [ Statement ]

10.2 Local Declaration Statements

LocalDeclarationStatement ::=
   LocalModifier LocalDeclarators StatementTerminator
LocalModifier ::= Static | Dim | Const
LocalDeclarators ::=
   LocalDeclarator | 
   LocalDeclarators , LocalDeclarator
LocalDeclarator ::=
   LocalIdentifiers [ As TypeName ] |
   LocalIdentifier [ As [ New ] TypeName [ ( [ ArgumentList ] ) ] ]
      [ = VariableInitializer ]
LocalIdentifiers ::=
   LocalIdentifier |
   LocalIdentifiers , LocalIdentifier
LocalIdentifier ::= Identifier [ ArrayNameModifier ]

10.3 With Statement

WithStatement ::=
   With Expression StatementTerminator
   [ Block ]
   End With StatementTerminator

10.4 SyncLock Statement

SyncLockStatement ::=
   SyncLock Expression StatementTerminator
   [ Block ]
   End SyncLock StatementTerminator

10.5 Event Statements

EventStatement ::=
   RaiseEventStatement |
   AddHandlerStatement |
   RemoveHandlerStatement

10.5.1 RaiseEvent Statement

RaiseEventStatement ::= RaiseEvent SimpleNameExpression
   [ ( [ ArgumentList ] ) ] StatementTerminator

10.5.2 AddHandler and RemoveHandler Statements

AddHandlerStatement ::= 
   AddHandler Expression , Expression StatementTerminator
RemoveHandlerStatement ::=
   RemoveHandler Expression , Expression StatementTerminator

10.6 Assignment Statements

AssignmentStatement ::=
   RegularAssignmentStatement |
   CompoundAssignmentStatement |
   MidAssignmentStatement

10.6.1 Regular Assignment Statements

RegularAssignmentStatement ::=
   Expression = Expression StatementTerminator

10.6.2 Compound Assignment Statements

CompoundAssignmentStatement ::=
   Expression CompoundBinaryOperator = Expression StatementTerminator
CompoundBinaryOperator ::= ^ | * | / | \ | + | - | & | < < | > >

10.6.3 Mid Assignment Statement

MidAssignmentStatement ::=
   Mid [ $ ] ( Expression , Expression [ , Expression ] ) =
      Expression StatementTerminator

10.7 Invocation Statements

InvocationStatement ::= [ Call ] InvocationExpression StatementTerminator

10.8 Conditional Statements

ConditionalStatement ::= IfStatement | SelectStatement

10.8.1 If...Then...Else Statements

IfStatement ::= BlockIfStatement | LineIfThenStatement
BlockIfStatement ::=
   If Expression [ Then ] StatementTerminator
   [ Block ]
   [ ElseIfStatement+ ]
   [ ElseStatement ]
   End If StatementTerminator
ElseIfStatement ::=
   ElseIf Expression [ Then ] StatementTerminator
   [ Block ]
ElseStatement ::=
   Else StatementTerminator
   [ Block ]
LineIfThenStatement ::=
   If Expression Then [Statements ] [ Else Statements ]
      StatementTerminator

10.8.2 Select...Case Statements

SelectStatement ::=
   Select [ Case ] Expression StatementTerminator
   [ CaseStatement+ ]
   [ CaseElseStatement ]
   End Select StatementTerminator
CaseStatement ::=
   Case CaseClauses StatementTerminator
   [ Block ]
CaseClauses ::=
   CaseClause |
   CaseClauses , CaseClause
CaseClause ::=
   [ Is ] ComparisonOperator Expression |
   Expression [ To Expression ]
ComparisonOperator ::= = | < > | < | > | = > | = <
CaseElseStatement ::=
   Case Else StatementTerminator
   [ Block ]

10.9 Loop Statements

LoopStatement ::=
   WhileStatement |
   DoLoopStatement |
   ForStatement |
   ForEachStatement

10.9.1 While...End While and Do...Loop Statements

WhileStatement ::=
   While Expression StatementTerminator
   [ Block ]
   End While StatementTerminator
DoLoopStatement ::=
   Do [ WhileOrUntil Expression ] StatementTerminator
   [ Block ]
   Loop [ WhileOrUntil Expression ] StatementTerminator
WhileOrUntil ::= While | Until

10.9.2 For...Next Statements

ForStatement ::=
   For LoopControlVariable = Expression To Expression [ Step Expression ]
      StatementTerminator 
   [ Block ]
   Next [ NextExpressionList ] StatementTerminator
LoopControlVariable ::=
   Identifier As TypeName |
   Expression
NextExpressionList ::=
   Expression |
   NextExpressionList , Expression

10.9.3 For Each...Next Statements

ForEachStatement ::=
   For Each LoopControlVariable In Expression StatementTerminator
   [ Block ]
   Next [Expression ] StatementTerminator

10.10 Exception-Handling Statements

ErrorHandlingStatement ::=
   StructuredErrorStatement |
   UnstructuredErrorStatement

10.10.1 Structured Exception-Handling Statements

StructuredErrorStatement ::=
   ThrowStatement |
   TryStatement
TryStatement ::=
   Try StatementTerminator
   [ Block ]
   [ CatchStatement+ ]
   [ FinallyStatement ]
   End Try StatementTerminator

10.10.1.1 Finally Blocks

FinallyStatement ::=
   Finally StatementTerminator
   [ Block ]

10.10.1.2 Catch Blocks

CatchStatement ::=
   Catch [ Identifier As TypeName ] [ When BooleanExpression ]
      StatementTerminator
   [ Block ]

10.10.1.3 Throw Statement

ThrowStatement ::= Throw [ Expression ] StatementTerminator

10.10.2 Unstructured Exception-Handling Statements

UnstructuredErrorStatement ::=
   ErrorStatement |
   OnErrorStatement |
   ResumeStatement

10.10.2.1 Error Statement

ErrorStatement ::= Error Expression StatementTerminator

10.10.2.2 On Error Statement

OnErrorStatement ::= On Error ErrorClause StatementTerminator
ErrorClause ::=
   GoTo - 1 |
   GoTo 0 |
   GotoStatement |
   Resume Next

10.10.2.3 Resume Statement

ResumeStatement ::= Resume [ ResumeClause ] StatementTerminator
ResumeClause ::= Next | LabelName

10.11 Branch Statements

BranchStatement ::=
   GotoStatement |
   ExitStatement |
   StopStatement |
   EndStatement |
   ReturnStatement
GotoStatement ::= GoTo LabelName StatementTerminator
ExitStatement ::= Exit ExitKind StatementTerminator
ExitKind ::= Do | For | While | Select | Sub | Function | Property | Try
StopStatement ::= Stop StatementTerminator
EndStatement ::= End StatementTerminator
ReturnStatement ::= Return [ Expression ]

10.12 Array-Handling Statements

ArrayHandlingStatement ::=
   RedimStatement |
   EraseStatement

10.12.1 ReDim Statement

RedimStatement ::= ReDim [ Preserve ] RedimClauses StatementTerminator
RedimClauses ::=
   RedimClause |
   RedimClauses , RedimClause
RedimClause ::= Expression ArraySizeInitializationModifier

10.12.2 Erase Statement

EraseStatement ::= Erase EraseExpressions StatementTerminator
EraseExpressions ::=
   Expression |
   EraseExpressions , Expression

11. Expressions

Expression ::=
   SimpleExpression |
   TypeExpression |
   MemberAccessExpression |
   DictionaryAccessExpression |
   IndexExpression |
   NewExpression |
   CastExpression |
   OperatorExpression

11.2 Constant Expressions

ConstantExpression ::= Expression

11.4 Simple Expressions

SimpleExpression ::=
   LiteralExpression |
   ParenthesizedExpression |
   InstanceExpression |
   SimpleNameExpression |
   AddressOfExpression

11.4.1 Literal Expressions

LiteralExpression ::= Literal

11.4.2 Parenthesized Expressions

ParenthesizedExpression ::= ( Expression )

11.4.3 Instance Expressions

InstanceExpression ::= Me | MyClass | MyBase

11.4.4 Simple Name Expressions

SimpleNameExpression ::= Identifier

11.4.5 AddressOf Expressions

AddressOfExpression ::= AddressOf Expression

11.5 Type Expressions

TypeExpression ::=
   GetTypeExpression |
   TypeOfIsExpression |
   IsExpression

11.5.1 GetType Expressions

GetTypeExpression ::= GetType ( TypeName )

11.5.2 TypeOf...Is Expressions

TypeOfIsExpression ::= TypeOf Expression Is TypeName

11.5.3 Is Expressions

IsExpression ::= Expression Is Expression

11.6 Member Access Expressions

MemberAccessExpression ::=
   [ [ MemberAccessBase ] . ] IdentifierOrKeyword
MemberAccessBase ::= Expression | BuiltInTypeName

11.7 Dictionary Member Access

DictionaryAccessExpression ::= [ Expression ] ! IdentifierOrKeyword

11.8 Invocation Expressions

InvocationExpression ::= Expression [ ( [ ArgumentList ] ) ]
ArgumentList ::=
   PositionalArgumentList , NamedArgumentList |
   PositionalArgumentList |
   NamedArgumentList
PositionalArgumentList ::=
   Expression |
   PositionalArgumentList , [ Expression ]
NamedArgumentList ::=
   IdentifierOrKeyword : = Expression |
   NamedArgumentList , IdentifierOrKeyword : = Expression

11.9 Index Expressions

IndexExpression ::= Expression ( [ ArgumentList ] )

11.10 New Expressions

NewExpression ::=
   ObjectCreationExpression |
   ArrayCreationExpression |
   DelegateCreationExpression

11.10.1 Object-Creation Expressions

ObjectCreationExpression ::= New TypeName [ ( [ ArgumentList ] ) ]

11.10.2 Array-Creation Expressions

ArrayCreationExpression ::=
   New TypeName [ ArraySizeInitializationModifier ]
      ArrayElementInitializer

11.10.3 Delegate-Creation Expressions

DelegateCreationExpression ::= New TypeName ( Expression )

11.11 Cast Expressions

CastExpression ::=
   DirectCast ( Expression , TypeName ) |
   CType ( Expression , TypeName ) |
   CastTarget ( Expression )
CastTarget ::=
   CBool | CByte | CChar | CDate | CDec | CDbl | 
   CInt | CLng | CObj | CShort | CSng | CStr

11.12 Operator Expressions

OperatorExpression ::=
   ArithmeticOperatorExpression |
   RelationalOperatorExpression |
   LikeOperatorExpression |
   ConcatenationOperatorExpression |
   ShortCircuitLogicalOperatorExpression |
   LogicalOperatorExpression |
   ShiftOperatorExpression

11.13 Arithmetic Operators

ArithmeticOperatorExpression ::=
   UnaryPlusExpression |
   UnaryMinusExpression |
   AdditionOperatorExpression |
   SubtractionOperatorExpression |
   MultiplicationOperatorExpression |
   DivisionOperatorExpression |
   ModuloOperatorExpression |
   ExponentOperatorExpression

11.13.1 Unary Plus Operator

UnaryPlusExpression ::= + Expression

11.13.2 Unary Minus Operator

UnaryMinusExpression ::= - Expression

11.13.3 Addition Operator

AdditionOperatorExpression ::= Expression + Expression

11.13.4 Subtraction Operator

SubtractionOperatorExpression ::= Expression - Expression

11.13.5 Multiplication Operator

MultiplicationOperatorExpression ::= Expression * Expression

11.13.6 Division Operators

DivisionOperatorExpression ::=
   FPDivisionOperatorExpression |
   IntegerDivisionOperatorExpression
FPDivisionOperatorExpression ::= Expression / Expression
IntegerDivisionOperatorExpression ::= Expression \ Expression

11.13.7 Mod Operator

ModuloOperatorExpression ::= Expression Mod Expression

11.13.8 Exponentiation Operator

ExponentOperatorExpression ::= Expression ^ Expression

11.14 Relational Operators

RelationalOperatorExpression ::=
   Expression = Expression |
   Expression < > Expression |
   Expression < Expression |
   Expression > Expression |
   Expression < = Expression |
   Expression > = Expression

11.15 Like Operator

LikeOperatorExpression ::= Expression Like Expression

11.16 Concatenation Operator

ConcatenationOperatorExpression ::= Expression & Expression

11.17 Logical Operators

LogicalOperatorExpression ::=
   Not Expression |
   Expression And Expression |
   Expression Or Expression |
   Expression Xor Expression

11.17.1 Short-circuiting Logical Operators

ShortCircuitLogicalOperatorExpression ::=
   Expression AndAlso Expression |
   Expression OrElse Expression

11.18 Shift Operators

ShiftOperatorExpression ::=
   Expression << Expression |
   Expression >> Expression
Show:
© 2015 Microsoft