Section H.4. Conditional Compilation Constants


H.4. Conditional Compilation Constants

Visual Basic includes support for conditional compilation in your source code through the #Const and #If directives. While you can add your own constants , there are several predefined constants available for use in conditionally compiling your code.

Constant

Description

CONFIG

New in 2005. This string indicates the current solution configuration in effect for the project from within the Visual Studio IDE. Typically, this constant is set to "Debug" or "Release." This constant is not set by default when using the command-line compiler.

DEBUG

A Boolean value that indicates whether debugging should be enabled (true) or disabled (False) in the compiled output. Code in the System.Diagnostics.Debug class responds to this constant. You can also use it to limit your own code. This constant is not set by default when using the command-line compiler.

TARGET

New in 2005. This string indicates the output target type as defined through the /target command-line switch. One of the following values: "exe" (console application), "winexe" (Windows application), "library" (DLL), or "module" (a ".netmodule" for later use in an assembly).

TRACE

A Boolean value that indicates whether tracing should be enabled (true) or disabled (False) in the compiled output. Code in the System.Diagnostics.Trace class responds to this constant. You can also use it to limit your own code. This constant is not set by default when using the command-line compiler.

VBC_VER

New in 2005. A numeric value that indicates the version number of Visual Basic being used to compile the application. Always in major.minor format. The Visual Basic 2005 compiler sets this constant to 8.0.

_MYAPPLICATIONTYPE

New in 2005. Indicates the type of Windows-based (not Web-based) application for the active project. Set automatically based on the _MYTYPE compiler constant value. One of the following values.

  • "Console" when _MYTYPE is set to "Console" or "WindowsFormsWithCustomSubMain"

  • "Windows" when _MYTYPE is set to "Windows" or "" (empty string)

  • "WindowsForms" when _MYTYPE is set to "WindowsForms"

For other _MYTYPE values, this constant is undefined. The My.Application namespace branch is unavailable when this constant is not one of the values listed above. When My.Application is available, its functionality varies based on this constant.

_MYCOMPUTERTYPE

New in 2005. Indicates whether the active application is a Windows-based or Web-based application. Set automatically based on the _MYTYPE compiler constant value. One of the following values.

  • "Web" for Web-based applications when _MYTYPE is set to "Web" or "WebControl"

  • "Windows" for Windows-based applications when _MYTYPE is set to "Console," "Windows," "" (empty string), "WindowsForms," or "WindowsFormsWithCustomSubMain"

For other _MYTYPE values, this constant is undefined. The My.Computer namespace branch is unavailable when this constant is not one of the values listed above. When My.Computer is available, its functionality varies based on this constant.

_MYFORMS

New in 2005. Indicates whether the My.Forms namespace branch is available in the application. Set automatically based on the _MYTYPE compiler constant value. One of the following Boolean values.

  • true when _MYTYPE is set to "WindowsForms" or "WindowsFormsWithCustomSubMain"

  • False when _MYTYPE is set to "Web" or "WebControl"

For other _MYTYPE values, this constant is undefined. The My.Forms namespace branch is only available when this constant is set to TRue.

_MYTYPE

New in 2005. Indicates the general project type of the current application. This setting and others that begin with "_MY" are used in conjunction with the My namespace feature. Although this value is set automatically, if you choose to override it, you will alter the availability of different portions of the My namespace hierarchy. One of the following values.

  • "Console" for console applications and windows services.

  • "Custom" for a custom solution that disables most My namespace features. This value is never set automatically.

  • "Web" for an ASP.NET-based standard application.

  • "WebControl" for an ASP.NET-based web control application.

  • "Windows" for a Windows Forms class library or control library. A _MYTYPE value of "" (empty string) has the same application impact as a setting of "Windows."

  • "WindowsForms" for a Windows Forms application.

  • "WindowsFormsWithCustomSubMain" for a Windows Forms application that has been altered to use a custom Sub Main entry point.

The My.Log, My.Request, and My.Response namespace branches are available only when this constant is set to "Web."

_MYUSERTYPE

New in 2005. Indicates the functionality of the My.User namespace branch. Set automatically based on the _MYTYPE compiler constant value. Always set to the same value as the _MYCOMPUTERTYPE constant.

  • "Web" for Web-based applications when _MYTYPE is set to "Web" or "WebControl"

  • "Windows" for Windows-based applications when _MYTYPE is set to "Console," "Windows," "" (empty string), "WindowsForms," or "WindowsFormsWithCustomSubMain"

For other _MYTYPE values, this constant is undefined. The My.User namespace branch is unavailable when this constant is not one of the values listed above. When My.User is available, its functionality varies based on this constant.

_MYWEBSERVICES

New in 2005. Indicates whether the My.WebServices namespace branch is available in the application. Set automatically based on the _MYTYPE compiler constant value. One of the following Boolean values.

  • true when _MYTYPE is set to "WebControl," "Windows," "" (empty string), "WindowsForms," or "WindowsFormsWithCustomSubMain"

  • False when _MYTYPE is set to "Web"

For other _MYTYPE values, this constant is undefined. The My.WebServices namespace branch is only available when this constant is set to TRue.





Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net