Writing Professional Visual Basic Applications
- A Brief Look at What's New in Visual Basic.NET
- Taking a Brief Look at the .NET Framework
- What Makes a Professional Application?
- Starting a Demo Project
- Controls Added to the Toolbox
- Making Controls Come Alive
Welcome to the next generation of Visual Basic. In every new release of Visual Basic, Microsoft has added many new features, enhanced some others, and removed or replaced some older capabilities. With the release of Visual Basic.NET, Microsoft has done it again. In fact, Visual Basic.NET brings together new technologies that will make your applications more efficient, easier to deploy, and Web-enabled.
Today, you get a quick look at what Visual Basic.NET is, and what's new in this version. Along the way, you will get an idea of the work involved in upgrading older applications from VB6 to VB.NET. One of the biggest changes that Microsoft has made is the inception of the .NET Framework. We will introduce this new environment today and cover it in a little more detail on Day 4, "Understanding the .NET Framework." You also will look at what it takes to transition from Visual Basic 6 to the new .NET environment.
You will also see what drives the type of application you're creating. This involves choosing an application that makes sense and creating a life cycle or project plan for the application that takes it from an idea to the final product.
Also, you'll start a new demo project in Visual Basic. Although you probably know how to do this already, it's a good idea to review it. You do this not just for the steps needed, but to discuss the options available to you with the project properties, focusing on what they can do for you during the development and testing process. Naming conventions will also be covered; however, you won't be shown lists of what they should be. Instead, you'll learn why you need them and how they should be used.
Finally, at the end of today's lesson, some of the more advanced controls and features included in Visual Basic will be covered. You'll see what they are, how to use them individually and together, and—more importantly—why you should use them.
A Brief Look at What's New in Visual Basic.NET
Visual Basic.NET is the next version of Visual Basic. Rather than simply add some new features to Visual Basic 6.0, Microsoft reengineered the product to make it easier than ever before to write distributed applications such as Web and enterprise systems. Visual Basic.NET has two new packages for creating forms (Windows Forms and Web Forms); a new version of ADO for accessing disconnected data sources; and has streamlined the language, removing older, unused keywords, among other changes.
These new features will allow you to create both client/server applications and Internet-based applications. With Web Forms and ADO.NET, you can now rapidly develop scalable Web sites. With the addition of inheritance, the language is now an object-oriented programming environment. Windows Forms natively supports accessibility and visual inheritance. Finally, deploying your applications is now as simple as copying your executables and components from directory to directory.
Also, Visual Basic.NET is now fully integrated with the other Microsoft Visual Studio.NET languages. Not only can you develop application components in different programming languages, but also your classes can now inherit from classes written in other languages using cross-language inheritance. With the unified debugger, you can now debug multiple language applications, whether they are running locally or on remote computers. Finally, whatever language you use, the Microsoft .NET Framework provides a rich set of APIs for use in Windows and the Internet.
Changes to the Visual Basic Language
Whereas earlier versions of Visual Basic had been directed toward standard client applications, Visual Basic.NET is intended for creating Web service applications as well as the standard Windows client applications. This is done by generating managed code for the .NET framework and Common Runtime (discussed later in this section). This, of course, required significant changes to the Visual Basic language.
Although Visual Basic has retained many of its original features, modified and enhanced others, and added new features, it's inevitable that this led to some inconsistency and redundancy within the language. With the major changes required for the .NET Framework and runtime, Microsoft decided that it was a good opportunity to clean up many of the outdated aspects of the Visual Basic language.
The changes that were made are intended to do the following:
Simplify the language and make it more consistent
Add new features that have been requested
Make the code easier to read and maintain
Enhance the error processing
Make applications easier to debug
The New Windows Forms
Windows Forms is part of the new.NET Framework and leverages many new technologies including a common application framework, managed execution environment, integrated security, and object-oriented design principles. Windows Forms also offers full support for quickly and easily connecting to XML Web services and building rich, data-aware applications based on the ADO.NET data model. With the new shared development environment in Visual Studio, developers can create Windows Forms applications with any languages supporting the .NET platform.
Creating a Windows Forms application is done much the same way as it was done in previous releases of Visual Basic. Controls are placed on the form and then positioned as required. To edit the source code, simply double-click a control to open the source editor.
Visual inheritance is one key new feature available in Windows Forms that will enhance developer productivity and facilitate code reuse. For example, you could define a standard main form that contains items such as a standard main menu and perhaps a common toolbar. This form can be used in other applications through inheritance and extended to meet the requirements of specific applications while promoting a common user interface and reducing the need to re-create the same forms. The creator of this base form or template can specify which elements can be extended and which must be used as-is, ensuring that the form is reused appropriately.
Precision Form Design
With the new Windows Forms, you now have an unprecedented level of control and productivity when designing the look and feel of your applications. Features such as the Menu Designer, Anchoring, Docking, and many other new controls enable a higher level of power and precision for developers building rich Windows-based user interfaces.
Windows Forms provides you with a rich set of technologies for building Windows-based applications. Not only are there new controls and features for fine-tuning the user interface, but Windows Forms also provides flexible deployment and integrated security.
The New Web Forms
Web Forms was created to address the differences between the techniques in use to build a Windows application and those used to create a Web application. With Visual Basic.NET you can now rapidly develop applications that will run on the Internet using the exact same techniques that you have already learned in Visual Basic.
To create a Web application, simply add a Web Form to your project, drag the controls you need onto the page, and then double-click each control to add the code required. Web Forms provides the following advantages:
Separates the HTML layout from the code behind the page. This separation makes it easier to update either piece independently of the other, simplifying code navigation and enabling code to be versioned more easily
Greatly enhances runtime performance because the code behind the HTML page is compiled into an executable, not script
Generates HTML pages in HTML 3.2, which means the page can be viewed on any platform, with any browser. Alternatively, you can target the special capabilities of a specific browser or wireless device
Previous versions of Visual Studio tools have attempted to simplify Web development. For example, Visual Basic provided support for DHTML clients and WebClasses while Visual InterDev assisted in the development of Active Server Pages (ASP). Web Forms address these issues and are the fundamental way to build Web applications with Visual Basic.NET. Web Forms represent an evolution of ASP and WebClasses providing the best of both models.
Transitioning from Visual Basic 6
Microsoft considered two options when designing Visual Basic.NET: retrofit the existing code base to run on top of the .NET Framework, or build from the ground up, taking full advantage of the platform. To deliver the features most requested by customers (for example, inheritance and threading) and ensure that Visual Basic moves forward into the next generation of Web applications, the decision was made to build Visual Basic.NET from the ground up on the new .NET Framework.
Visual Basic.NET enables a fundamental shift from traditional Windows development to building next-generation Web and Windows applications. For this reason, your code will need to be upgraded to take advantage of Visual Basic.NET. Thankfully, Microsoft has provided an Upgrade Wizard to help you perform this task. When you open a Visual Basic 6 project in Visual Basic.NET, the Upgrade Wizard will automatically start to step you through the upgrade process and will create a new Visual Basic.NET project, leaving your existing project untouched.
When your project is upgraded, the language is modified for any syntax changes and your Visual Basic 6.0 Forms are converted to Windows Forms. In most cases, you will have to make some changes to your code after it's upgraded. This is required because certain objects and language features either have no equivalent in Visual Basic.NET, or have an equivalent too different for an automatic upgrade. After the upgrade, you may also want to modify your application to take advantage of some newer features in Visual Basic.NET.
When you use the Upgrade Wizard, most required language and object changes will be made for you. The Upgrade Wizard is started when you open a Visual Basic 6 application. It will ask you about the project type and set options for your application (see Figure 1.1). At this moment, leave the defaults displayed.
Figure 1.1 Upgrading your Visual Basic 6 application using the wizard.
The next step is to specify where you want the new .NET project to be saved. Remember that your original project won't be modified. Once completed, the new project will remain open in the Solutions Explorer. You can then display the Upgrade report to see what issues you need to resolve as shown in Figure 1.2.
Figure 1.2 Working with the Upgrade report to resolve Visual Basic language issues.
Two very good documents are available from the Microsoft Visual Basic.NET Web site:
Preparing Your VB 6 Applications for the Upgrade to VB.NET
The Transition from Visual Basic 6.0 to Visual Basic.NET