- VB 6 Versus Visual Basic .NET
- Changing a Class
- The Project
- The Challenges
- The New Kid: TextFieldParser
- Why Use the My Object?
- Summary
Why Use the My Object?
I'm certain that some who read this will want to know why anyone should leave VB 6 and that familiar syntax that makes us productive quickly. When you study the work of efficiency experts, you often find that the sum of several incremental improvements provide as much value as massive changes. This example didn't take long to do, despite the perceived professionalism shown in the interface. As I worked through the example, I was impressed with the straightforward syntax of the My object. But is that enough to convince others to switch to .NET? I think so.
I know, on the other side of this learning curve, I have the vastness of the .NET Framework that saves me the cost of custom controls for minor routine uses such as file transfers and getting web pages. If I want, there's a world of wonderful controls to improve my interfaces; for example, from such outstanding vendors as Infragistics. I have better error reporting, with examples in the help pages that are usable immediately. And cutting and pasting sample code from the help pages has never been easier. But this example is file parsing. Is there more out there that will help me transition to .NET faster?
The story doesn't end here. This article covers only one small section of just one of the My objects. Table 1 lists the My objects and their functions. Within the namespace you'll find objects that let you navigate and use the Framework far faster than any other version of Visual Basic .NET.
Table 1 My Family of Helpful Objects
My Object Family |
Abilities |
My.Application |
Allows the coder to do application "final touches"—logging activity, parsing/reading command-line arguments passed, creating splash screens, etc. |
My.Computer |
Allows the coder to investigate the computer the application is running on at runtime. Need an easy way to see whether the computer is network connected? Need to upload/download files? Need to get items from the Clipboard? Last, do you want to play an audio file? The My.Computer object and all its descendants make these tasks much easier than using the Win API functions in VB 6. |
My.Forms |
Allows the coder to keep track of and display/hide forms easily. Need to control another form in your application? This object enables it well. |
My.Resources |
Provides a convenient way to access your application's resources—bitmaps, sounds, etc. Need to access them dynamically? This object makes it much easier over stock .NET functionality. |
My.Settings |
Applications need to manage user and application settings easily. This object makes it simpler. Imagine each setting being a nice object with well-defined methods? This object enables great personalization without having to create a lot of code. |
My.User |
This is an excellent way to query the user's identity and authorizations. As security becomes more important, this object helps your application understand the user at runtime. |
My.WebServices |
Consuming web services is a necessary ability for modern web applications. This object facilitates this goal, including using WebServices via a background Worker task. |