Customizing Which Objects are Available in My (Visual Basic)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

This topic describes how you can control which My objects are enabled by setting your project's _MYTYPE conditional-compilation constant. The Visual Studio Integrated Development Environment (IDE) keeps the _MYTYPE conditional-compilation constant for a project in sync with the project's type.

You must use the /define compiler option to set the _MYTYPE conditional-compilation constant. When specifying your own value for the _MYTYPE constant, you must enclose the string value in backslash/quotation mark (\") sequences. For example, you could use:


This table shows what the _MYTYPE conditional-compilation constant is set to for several project types.

Project type_MYTYPE value
Class Library"Windows"
Console Application"Console"
Web Control Library"WebControl"
Windows Application"WindowsForms"
Windows Application, when starting with custom Sub Main"WindowsFormsWithCustomSubMain"
Windows Control Library"Windows"
Windows Service"Console"
System_CAPS_ICON_note.jpg Note

All conditional-compilation string comparisons are case-sensitive, regardless of how the Option Compare statement is set.

The _MYTYPE conditional-compilation constant, in turn, controls the values of several other _MY compilation constants:

"Windows" or """Windows""Windows"Undefined"Windows"TRUE

By default, undefined conditional-compilation constants resolve to FALSE. You can specify values for the undefined constants when compiling your project to override the default behavior.

System_CAPS_ICON_note.jpg Note

When _MYTYPE is set to "Custom", the project contains the My namespace, but it contains no objects. However, setting _MYTYPE to "Empty" prevents the compiler from adding the My namespace and its objects.

This table describes the effects of the predefined values of the _MY compilation constants.

_MYAPPLICATIONTYPEEnables My.Application, if the constant is "Console," Windows," or "WindowsForms":

- The "Console" version derives from ConsoleApplicationBase. and has fewer members than the "Windows" version.
- The "Windows" version derives from ApplicationBase.and has fewer members than the "WindowsForms" version.
- The "WindowsForms" version of My.Application derives from WindowsFormsApplicationBase. If the TARGET constant is defined to be "winexe", then the class includes a Sub Main method.
_MYCOMPUTERTYPEEnables My.Computer, if the constant is "Web" or "Windows":

- The "Web" version derives from ServerComputer, and has fewer members than the "Windows" version.
- The "Windows" version of My.Computer derives from Computer.
_MYFORMSEnables My.Forms, if the constant is TRUE.
_MYUSERTYPEEnables My.User, if the constant is "Web" or "Windows":

- The "Web" version of My.User is associated with the user identity of the current HTTP request.
- The "Windows" version of My.User is associated with the thread's current principal.
_MYWEBSERVICESEnables My.WebServices, if the constant is TRUE.
_MYTYPEEnables My.Log, My.Request, and My.Response, if the constant is "Web".

How My Depends on Project Type
Conditional Compilation
/define (Visual Basic)
My.Forms Object
My.Request Object
My.Response Object
My.WebServices Object