Using the My Object in Visual Basic 2008
The most impressive single language feature in Visual Basic 2008 is the My object. The My object is an object that exposes commonly used .NET technology through an easy-to-understand hierarchy. In short, it is a set of shortcuts into the .NET Framework.
The following table highlights the core classes and common functionality of the My object:
|My Object Class Name||What It Does||Cool Functionality|
|My.Application||Returns information about and services provided by the current
|The NetworkAvailabilityChanged event is fired when the
computer running the application connects to or disconnects from
|My.Computer||Provides access to resources, devices, and data related to the
computer running the application currently.
|Look at My.Computer.Clipboard for methods like
GetText(), which reads from the Windows Clipboard.
|My.Forms||Provides everything you need to know about all of the forms in
the current project.
|My.Forms allows you to use Visual Basic 6–like
functionality built into Windows Forms.
|My.Log||Grants access to the ASP.NET application log listeners, which
can handle log entries in a myriad of ways.
|Look at the <listeners> section of the
Web.Config file, where you can determine where the Log class
is writing to.
|My.Request||Provides access to the current Web request for ASP.NET
|Use My.Request to see ASP classic-type access to the
Request, such as My.Request.Headers (the HTTP Web
|My.Resources||Exposes global application resources.||Change the form icon (to show a change in status, for example)
|My.Response||Grants access to the current Web response for ASP.NET
|Use My.Response to see ASP classic-type access to the
Response, like My.Response.Write.
|My.Settings||Gives the ability to store and retrieve the application-level
settings for the current program.
|Change application-level settings at runtime (finally). Set up
the settings in the Application Project Designer, and then use
My.Settings.SettingName to change it at runtime.
|My.User||Provides security context information for the user logged into
the computer using the application.
|Personalize your application with the current user’s
name. Check out My.User.Name.
|My.Services||Provides access to the Web services referenced by the
|After you have referenced a Web Service, you can call it with