Introduction

In 2002, Visual Basic took the biggest leap in innovation since it was released, with the introduction of Visual Basic .NET (as it was renamed). After more than a decade, Visual Basic was overdue for a major overhaul. Nevertheless, .NET goes beyond an overhaul. It changes almost every aspect of software development. From integrating Internet functionality to creating object-oriented frameworks, Visual Basic .NET challenged traditional VB developers to learn dramatic new concepts and techniques.

2008 brought forth an even more enhanced Visual Basic language. New features have been added that cement this language's position as a true object-oriented language and provide better access to underlying data. Visual Basic 2008 is still going to be a challenge for traditional VB6 developers to learn, but it's an easy road for those with any familiarity with previous versions, and this book is here to help you on your way.

This .NET Framework 3.5 version of this book provides details about not only the latest version of Visual Basic — version 2008 — but also the new framework that gives Visual Basic developers the capability to build new application types using Windows Presentation Foundation (WPF) and applications and libraries based upon the Windows Communication Foundation (WCF), the Windows Workflow Foundation (WF), and Windows CardSpace. It also covers one of the more important features: LINQ.

These additions are what constitute the .NET Framework 3.5, as this version of the framework installs and works from the previous .NET Framework 2.0 and 3.0. This book includes numerous chapters that focus on the new technologies brought forth by the .NET Framework 3.0 and 3.5.

First, it is necessary to learn the differences between Visual Basic 2008 and the older versions of the language. In some cases, the same functionality is implemented in a different way. This was not done arbitrarily — there are good reasons for the changes. However, you must be prepared to unlearn old habits and form new ones.

Next, you must be open to the new concepts. Full object orientation, new component techniques, new visual tools for both local and Internet interfaces — all of these and more must become part of your skill set to effectively develop applications in Visual Basic.

This book covers Visual Basic from start to finish. We begin by looking at the .NET Framework and end by looking at the best practices for deploying .NET applications. In between, you will learn everything from database access to integration with other technologies such as XML, along with investigating the new features in detail. You will see that Visual Basic 2008 has emerged as a powerful yet easy-to-use language that enables you to target the Internet just as easily as the desktop. This book covers the .NET Framework 2.0, the .NET Framework 3.0, and the newly released .NET Framework 3.5. If you are coding using version 1.0, 1.1, or just 2.0, some sections of the book will not work for you. Items that are new to the .NET Framework 3.5 are specifically noted as such.

The Importance of Visual Basic

Early in the adoption cycle of .NET, Microsoft's new language, C#, got the lion's share of attention. However, as .NET adoption has increased, Visual Basic's continuing importance has also been apparent. Microsoft has publicly stated that it considers Visual Basic to be the language of choice for applications where developer productivity is one of the highest priorities.

Future development of Visual Basic is emphasizing capabilities that enable access to the whole expanse of the .NET Framework in the most productive way, while C# development is emphasizing the experience of writing code. That fits the traditional role of Visual Basic as the language developers use in the real world to create business applications as quickly as possible.

This difference is more than academic. One of the most important advantages of the .NET Framework is that it enables applications to be written with dramatically less code. In the world of business applications, the goal is to concentrate on writing business logic and to eliminate routine coding tasks as much as possible. In other words, of greatest value in this new paradigm is writing robust, useful applications with as little code as possible, not churning out a lot of code.

Visual Basic is an excellent fit for this type of development, which makes up the bulk of software development in today's economy. Moreover, it will grow to be an even better fit as it is refined and evolves for exactly that purpose.

Who This Book Is For

This book was written to help experienced developers learn Visual Basic 2008. From those who are just starting the transition from earlier versions to those who have used Visual Basic for a while and need to gain a deeper understanding, this book provides information on the most common programming tasks and concepts you need.

Professional Visual Basic 2008 offers a wide-ranging presentation of Visual Basic concepts, but the .NET Framework is so large and comprehensive that no single book can cover it all. The main area in which this book does not attempt to be complete is Web development. While chapters discussing the basics of browser-based programming in Visual Basic are included, professional Web developers should instead refer to Professional ASP.NET 3.5.

What You Need to Use This Book

Although it is possible to create Visual Basic applications using the command-line tools contained in the .NET Framework SDK, you need Visual Studio 2008 (Professional or higher), which includes the .NET Framework SDK, to get the most out of this book. You may use Visual Studio 2005, Visual Studio .NET 2002, or Visual Studio 2003 instead, but in some cases the exercises won't work because functionalities and capabilities are not available in these older versions. In addition, note the following:

  • You need the .NET Framework 3.5 (which will install the .NET Framework 2.0 by default if it isn't already present on the machine).

  • Some chapters make use of SQL Server 2005 and SQL Server 2008, but you can also run the example code using Microsoft's SQL Express, which ships with Visual Studio 2008.

  • Several chapters make use of Internet Information Services (IIS). IIS ships with Windows Vista, Windows Server 2008, Windows 2003 Server, Windows 2000 Server, Windows 2000 Professional, and Windows XP, although it is not installed by default.

  • Chapter 30 makes use of MSMQ to work with queued transactions. MSMQ ships with many Windows versions, but it is not installed by default.

What This Book Covers

Chapter 1, "Visual Basic 2008 Core Elements" — This chapter introduces many of the types commonly used in Visual Basic 2008. Topics discussed in this chapter include type coverage, type nversion, reference types, arrays, and other collections, parameter passing, and boxing. The full syntax basics of Visual Basic are provided in this chapter.

Chapter 2, "Object Syntax Introduction" — This is the first of three chapters that explore object-oriented programming in Visual Basic. This chapter defines objects, classes, instances, encapsulation, abstraction, polymorphism, and inheritance.

Chapter 3, "Object-Oriented Programming" — This chapter examines inheritance and how it can be used within Visual Basic. You create simple and abstract base classes and learn how to create base classes from which other classes can be derived. This chapter puts the theory for much of what has been discussed thus far into practice. The four defining object-oriented concepts (abstraction, encapsulation, polymorphism, inheritance) are described, and we explain how these concepts can be applied in design and development to create effective object-oriented applications.

Chapter 4, "The Common Language Runtime" — This chapter examines the core of the .NET platform: the common language runtime (CLR). The CLR is responsible for managing the execution of code compiled for the .NET platform. You learn about versioning and deployment, memory management, cross-language integration, metadata, and the IL Disassembler.

Chapter 5, "Localization" — Developers usually build applications in the English language. Then, as the audience for the application expands, they realize the need to globalize the application. Of course, the ideal is to build the application to handle an international audience right from the start — but in many cases, this isn't possible because of the extra work it requires. The .NET Framework made a considerable effort to address the internationalization of the applications you build. Changes to the API, the addition of capabilities to the server controls, and even Visual Studio itself equip you to do the extra work required more easily to bring your application to an international audience. This chapter looks at some of the important items to consider when building your applications for the world. It looks closely at the System.Globalization namespace and everything it offers your applications.

Chapter 6, "Generics" — This chapter focuses on one of the biggest enhancements to Visual Basic in this version — generics. Generics enables you to make a generic collection that is still strongly typed — providing fewer chances for errors, increasing performance, and giving you IntelliSense features when you are working with your collections.

Chapter 7, "Namespaces" — This chapter introduces namespaces and their hierarchical structure. An explanation of namespaces and some common examples are provided. In addition, you learn how to create new namespaces, and how to import and alias existing namespaces within projects. This chapter also looks at the My namespace available in Visual Basic.

Chapter 8, "Exception Handling and Debugging" — This chapter covers how error handling and debugging work in Visual Basic 2008 by discussing the CLR exception handler and the Try...Catch...Finally structure. Also covered are error and trace logging, and how you can use these methods to obtain feedback about how your program is working.

Chapter 9, "Data Access with ADO.NET 3.5" — This chapter focuses on what you need to know about the ADO.NET object model in order to build flexible, fast, and scalable data-access objects and applications. The evolution of ADO into ADO.NET is explored, and the main objects in ADO.NET that you need to understand in order to build data access into your .NET applications are explained.

Chapter 10, "Using XML in Visual Basic 2008" — This chapter presents the features of the .NET Framework that facilitate the generation and manipulation of XML. We describe the .NET Framework's XML-related namespaces, and a subset of the classes exposed by these namespaces is examined in detail. This chapter also touches on a set of technologies that utilize XML — specifically, ADO.NET and SQL Server. This chapter focuses on XML usage prior to LINQ.

Chapter 11, "LINQ" — This chapter presents one of the coolest and most anticipated features provided in the .NET Framework 3.5. LINQ offers the capability to easily access underlying data — basically a layer on top of ADO.NET. Microsoft has provided LINQ as a lightweight façade that provides a strongly typed interface to the underlying data stores. Using LINQ, you can query against objects, data sets, a SQL Server database, XML, and more.

Chapter 12, "Security in the .NET Framework" — This chapter examines additional tools and functionality with regard to the security provided by .NET. Caspol.exe and Permview.exe, which assist in establishing and maintaining security policies, are discussed. The System.Security.Permissions namespace is also covered, and we discuss how it relates to managing permissions. Finally, you look at the System.Security.Cryptography namespace and run through some code that demonstrates its capabilities.

Chapter 13, "Visual Studio 2008" — This chapter introduces the next generation of the major IDE for developing .NET applications: Visual Studio 2008. Previous releases of this IDE included Visual Studio .NET 2003, Visual Studio .NET 2002, and Visual Studio 2005. This chapter focuses on the Visual Studio 2008 release and how you can use it to build better applications more quickly.

Chapter 14, "Working with SQL Server" — This chapter describes how to work with the new SQL Server 2008 along with your .NET applications. SQL Server provides a strong connection to your applications, and this chapter explains how to effectively utilize this powerful database.

Chapter 15, "Windows Forms" — This chapter looks at Windows Forms, concentrating primarily on forms and built-in controls. What is new and what has been changed from previous versions of Visual Basic are discussed, along with the System.Windows.Forms namespace.

Chapter 16, "Windows Forms Advanced Features" — This chapter looks at some of the more advanced features that are available to you in building your Windows Forms applications.

Chapter 17, "Windows Presentation Foundation" — A component that was introduced in the .NET 3.0 and enhanced in the .NET Framework 3.5, Windows Presentation Foundation offers a new vehicle for building applications. This chapter describes the new way in which Microsoft is promoting the presentation of a GUI, and WPF provides a presentation layer that you should find rather fluid and enriching. This chapter describes the basics of WPF and how to build simple XAML-based applications.

Chapter 18, "Integrating WPF with Windows Forms" — Many organizations have made significant investments in Windows Forms, and they are not ready to fully switch their applications to this new technology. For this reason, Microsoft has provided significant means to integrate WPF into your Windows Forms applications, as well as the capability to bring your Windows Forms components to a WPF application. This chapter focuses on these capabilities.

Chapter 19, "Working with ASP.NET 3.5" — This chapter explores the basics of ASP.NET 3.5 in detail. It looks at building Web applications using Visual Studio 2008 and includes discussions on the overall application and page frameworks.

Chapter 20, "ASP.NET 3.5 Advanced Features" — This chapter looks at several of the advanced features that are available to you with the latest release of ASP.NET 3.5. Examples of items covered include cross-page posting, master pages, site navigation, personalization, and more.

Chapter 21, "Silverlight Development" — This chapter looks at the new technology for the Web provided by Silverlight. This new capability provides the means of using XAML and brings a more fluid experience to the end user in the browser.

Chapter 22, "Visual Studio Tools for Office" — This chapter looks at using Visual Basic to work with your Microsoft Office-focused applications.

Chapter 23, "Assemblies" — This chapter examines assemblies and their use within the CLR. The structure of an assembly, what it contains, and the information it contains are described. In addition, you will look at the manifest of the assembly and its role in deployment.

Chapter 24, "Deployment" — This chapter takes a close look at the available deployment options for Windows Forms and Web Forms, including the ClickOnce deployment feature and creating .msi files.

Chapter 25, "Working with Classic COM and Interfaces" — This chapter discusses COM and .NET component interoperability, and what tools are provided to help link the two technologies.

Chapter 26, "Threading" — This chapter explores threading and explains how the various objects in the .NET Framework enable any of its consumers to develop multithreaded applications. You will learn how threads can be created, how they relate to processes, and the differences between multitasking and multithreading.

Chapter 27, "Windows Workflow Foundation" — This chapter takes a look at this relatively new capability to easily integrate workflow into your applications. Windows Workflow was introduced in the .NET Framework 3.0, but it is a big part of .NET 3.5 and Visual Studio 2008.

Chapter 28, "XML Web Services" — This chapter describes how to create and consume Web services using VB 2008. The abstract classes provided by the CLR to set up and work with Web services are discussed, as well as some of the technologies that support Web services. Also examined are some of the disadvantages to using any distributed architecture, and the future of Web services.

Chapter 29, "Remoting" — This chapter takes a detailed look at how to use remoting in classic three-tier application design. You examine the basic architecture of remoting and build a basic server and client that uses a singleton object for answering client requests in the business tier. You will also learn how to use serialization to return more complex objects from the server to the client, and how to use the call context for passing extra data from the client to the server along with each call, without having to change the object model.

Chapter 30, "Enterprise Services" — This chapter explores the .NET component services — in particular, transaction processing and queued components.

Chapter 31, "Network Programming" — This chapter covers working with some of the networking protocols that are available to you in your development and how to incorporate a wider network into the functionality of your applications.

Chapter 32, "Windows Communication Foundation" — This chapter looks at the newest way to build service-oriented components that allow for standards-based communications over a number of protocols. WCF is Microsoft's latest answer for component communications within and outside of the enterprise.

Chapter 33, "Windows Services" — This chapter examines how Visual Basic is used in the production of Windows Services. The creation, installation, running, and debugging of Windows Services are covered.

Chapter 34, "Visual Basic and the Internet" — This chapter describes how to download resources from the Web, how to design your own communication protocols, and how to reuse the Web browser control in your applications.

Appendix A, "The Visual Basic Compiler" — This appendix covers the Visual Basic compiler vbc.exe and the functionality it provides.

Appendix B, "Visual Basic Power Packs Tools" — This appendix looks at the Visual Basic Power Packs Tools, a set of off-cycle release packages that focus on helping developers who are maintaining traditional Visual Basic 6.0 applications begin the process of transitioning to Visual Basic .NET.

Appendix C, "Visual Basic Resources" — This appendix provides a short list of VB resources available.

Conventions

To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.

Note

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

  • We italicize new terms and important words when we introduce them.

  • We show keyboard strokes like this: Ctrl+A.

  • We show filenames, URLs, and code within the text like so: persistence.properties.

  • We present code in two different ways:

    We use a monofont type with no highlighting for most code examples.
    We use gray highlighting to emphasize code that's particularly
    important in the present context.

Source Code

As you work through the examples in this book, you may choose to either type in all the code manually or use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. Once at the site, simply locate the book's title (either by using the Search box or by using one of the title lists) and click the Download Code link on the book's detail page to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-0-470-19136-1.

Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or a faulty piece of code, we would be very grateful for your feedback. By sending in errata, you may save another reader hours of frustration, and at the same time you will be helping us provide even higherquality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot "your" error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.

  2. Read the terms of use and click Agree.

  3. Complete the required information to join as well as any optional information you wish to provide and click Submit.

  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P, but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset