Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
Bing
BizTalk
Book Excerpts
Build and Deploy
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
Internet Explorer 8.0
Interviews
iPhone
Iron Ruby
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
Network
NHibernate
Object Oriented Development
Odata
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Python
Q&A
Rails
Rake
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Search
Security
Services
SharePoint
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



Hacker Halted


 


VFPConversion.com

Reader rating:
Click here to read 2 comments about this article.
Article source: CoDe (2004 - September/October)


Article Pages:  1  2 3 4 - Next >


Oh My!! - A Look at the My Namespace in Visual Basic 2005

Productivity is one of the major goals of Visual Basic 2005 and with "My" Microsoft may just have hit a home run. Although Visual Basic .NET is just as powerful as C# for building business applications, it did not get the initial push that C# did back at PDC 2000 when Microsoft unveiled .NET. This was not meant to slight Visual Basic and Visual Basic developers, but rather represented the state of the Visual Basic .NET language which was not as far along in the development process as C#. Opponents to the Basic syntax took this and ran with it. Microsoft has tried to attack this misconception but has also caused some of the problem, initially by pushing .NET for Web services development so hard that many developers and managers incorrectly got idea that .NET was primarily for Web services. With Visual Basic 2005 the power of the .NET Framework is fully exposed and the true power of Visual Basic is once again starting to take form and that power is productivity. Whereas C# is about language first and foremost Visual Basic is about language and tools to make the development process faster.

"
My makes retrieving settings and resources that your application requires simply more productive.
"

One of the language and tool innovations introduced in Visual Basic 2005 is the My namespace. This may seem like an odd name at first, but Microsoft created My to make it easier to execute common code patterns that developers use in .NET applications. Often these common code patterns, such as reading the text in a file, were made more confusing than necessary simply because the plethora of awesome choices that .NET provides. Although it is great to have many possible ways to accomplish a task, these choices may also lead to confusion for the developers new to the .NET Framework. My supplies shortcuts to some common boilerplate code such as invoking Web services referenced by the application, gaining access to information about the user, the computer, the network, etc. Some of the capabilities of My will result in less code and in some cases using My makes getting at information more intuitive. In this article I will show you some common tasks that the My namespace makes easier and I'll show how you can add to and extend My with your own information.

What's in My?

My is a shortcut to several categories of information and functionality. My provides rapid access to the following categories of information:

  • My.Computer - Access to information related to the computer such as file system, network, devices, system information, etc. My.Computer provides access to a number of very important resources including My.Computer.Network, My.Computer.FileSystem, and My.Computer.Printers.
  • My.Application - Access to information related to the particular application such as name, version, current directory, etc.
  • My.User - Access to information related to the current authenticated user.
  • My.Resources - Access to resources used by the application residing in resource files in a strongly typed manner.
  • My.Settings - Access to configuration settings of the application in a strongly typed manner.

My Makes Code More Intuitive

One of the reasons that Visual Basic is my preferred language for .NET development is that, in my opinion, using English words makes the intent of the code easier to grasp when someone new to the code looks at it for the first time. Software can be expensive to create, but more often then not it costs more to maintain custom software than to create it. I believe using the My namespace will help to make code easier to grasp when a new developer first looks at it. Let's look at a few examples where My cleans up the code. Note that in the remainder of the article I will refer to Visual Basic .NET 2003 as VB7.1 and I will refer to Visual Basic 2005 as VB8.

In a Windows Forms application you often need to know which directory the application is running in so you have access to data files, configuration information, etc. In VB7.1 to find the current directory of an application you could use the following function:

Public Function GetAppDirectory() as String
   Return System.IO.Directory.GetCurrentDirectory
End Function

Now that isn't difficult nor does it represent a great deal of code yet the code wasn't intuitive. In VB8 the code to get the current directory looks like this:

Public Function GetAppDirectory() as String
   Return My.Application.CurrentDirectory
End Function
&

By: Keith Franklin

Keith Franklin is the Chief Software Architect of a leading .NET consulting firm in Chicago. Keith is a Microsoft MVP, a regular speaker at VSLive!, DevDays, Microsoft launch events, and the Chicago .NET Users Group, which he founded and directs. His close relationship with members of the Microsoft .NET teams, publishers, speakers, and user group community led to his appointment to the Board of Directors of the International .NET Association (INETA) in September 2001. He authored one of the first Visual Basic books devoted to the .NET Framework. He has also authored numerous articles published by leading .NET and Visual Basic publications and is a member of the .NET Developers Journal editorial board.

ka_franklin@empowered.com

Fast Facts

Learn to use and extend the new My namespace features of Visual Studio .NET 2005



Article Pages:  1  2 3 4 - Next Page: 'My Makes Code More Intuitive (con't)' >>

Page 1: Oh My!! - A Look at the My Namespace in Visual Basic 2005
Page 2: My Makes Code More Intuitive (con't)
Page 3: My Reduces the Amount of Code You Write
Page 4: My Introduces Application-Level Events for Visual Basic

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.9 out of 5

21 people have rated this article.

      INSTANTLY dtSearch® TERABYTES OF TEXT

 

QCon