O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

#If . . . Then . . . #Else Directive

Syntax

#If expression Then
   statements
[#ElseIf furtherexpression Then
   [elseifstatements]]
[#Else
   [elsestatements]]
#End If
expression (required)

An expression made up of literals, operators, and conditional compiler constants that will evaluate to True or False

statements (required)

One or more lines of code or compiler directives, which is executed if expressionevaluates to True

furtherexpression (optional)

An expression made up of literals, operators, and conditional compiler constants that will evaluate to True or False. furtherexpression is only evaluated if the preceding expression evaluates to False

elseifstatements (optional)

One or more lines of code or compiler directives, which is executed if furtherexpression evaluates to True

elsestatements (optional)

One or more lines of code or compiler directives, which are executed if expression or furtherexpression evaluates to False

Description

Defines a block or blocks of code that are only included in the compiled application when a particular condition is met, allowing you to create more than one version of the application using the same source code.

Conditionally including a block of code is a two-step process:

  • Use the #Const directive to assign a value to a conditional compiler constant.

  • Evaluate the conditional compiler constant using the #If...Then...#End If statement block.

Only code blocks whose expressions evaluate to True are included in the executable. You can use the #Else statement ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required