Skip to main content

Professional VB.NET, 2nd Edition

Professional VB.NET, 2nd Edition

Fred Barwell, Richard Case, Bill Forgey, Billy Hollis, Tim McCarthy, Jonathan Pinnock, Richard Blair, Jonathan Crossland, Whitney Hankison, Rockford Lhotka, Jan D. Narkiewicz, Rama Ramachandran, Matthew Reynolds, John Roth, Bill Sheldon, Bill Sempf

ISBN: 978-0-764-54400-2

Apr 2002

1032 pages

Select type: Paperback

Product not available for purchase


What is this book about?

.NET is designed to provide a new environment within which you can develop almost any application to run on Windows (and possibly in the future on other platforms). Visual Basic .NET (VB.NET) is likely to be a very popular development tool for use with this framework. VB.NET is a .NET compliant language and, as such, has (except for legacy reasons) almost identical technical functionality as the new C# language and Managed Extensions for C++. Using VB.NET, you can develop a dynamic Web page, a component of a distributed application, a database access component, or a classic Windows desktop application.

In order to incorporate Visual Basic into the .NET Framework, a number of new features have been added to it. In fact, the changes are so extensive that VB.NET should be viewed as a new language rather than simply as Visual Basic 7. However, these changes were necessary to give developers the features that they have been asking for: true object orientated programming, easier deployment, better interoperability, and a cohesive environment in which to develop applications.

What does this book cover?

In this book, we cover VB.NET virtually from start to finish: We begin by looking at the .NET Framework, and end by looking at best practices for deploying .NET applications. In between, we look at everything from database access to integration with other technologies such as XML, along with investigating the new features in detail. You will see that VB.NET has emerged as a powerful yet easy to use language that will allow you to target the Internet just as easily as the desktop.

This book explains the underlying philosophy and design of the .NET Framework and Common Language Runtime (CLR) and explains the differences between Visual Basic 6 and Visual Basic .NET.

You will learn how to

  • Develop applications and components using Visual Studio .NET
  • Effectively apply inheritance and interfaces when designing objects and components
  • Organize your code using namespaces
  • Handle errors using the Try...Catch...Finally structure
  • Access data using ADO.NET and bind controls to the underlying data sources
  • Create Windows applications and custom Windows controls
  • Interoperate with COM and ActiveX components
  • Create transactional and queuing components
  • Use .NET Remoting to send serialized objects between clients and servers
  • Create Windows Services
  • Use VB.NET to access information on the Web
  • Create and consume Web Services
  • Secure your applications and code using the tools provided in the .NET Framework SDK
  • Arrange your applications and libraries in assemblies and deploy them using Visual Studio .NET

Who is this book for?

This book is aimed at experienced Visual Basic developers who want to make the transition to VB.NET.

What do you need to use this book?

Although it is possible to create VB.NET applications using the command lines tools contained in the .NET Framework SDK, you will need Visual Studio .NET (Professional or higher), which includes the .NET Framework SDK, to use this book to the full.

Here are some additional notes on what you may need:

  • Some chapters make use of SQL Server 2000. However, you can also run the example code using MSDE (Microsoft Data Engine), which ships with Visual Studio .NET.
  • Several chapters make use of Internet Information Services (IIS). IIS ships with Windows 2000 Server, Windows 2000 Professional, and Windows XP, although it is not installed by default.
  • Chapter 18 makes use of MSMQ to work with queued transactions. MSMQ ships with Windows 2000 Server, Windows 2000 Professional, and Windows XP, although it is not installed by default.
Chapter 1: What is Microsoft .NET?

Chapter 2: Introducing VB.NET and VS.NET.

Chapter 3: The Common Language Runtime.

Chapter 4: Variables and Types.

Chapter 5: Object Syntax Introduction.

Chapter 6: Inheritance and Interfaces.

Chapter 7: Applying Objects and Components.

Chapter 8: Namespaces.

Chapter 9: Error Handling.

Chapter 10: Using XML in VB.NET.

Chapter 11: Data Access with ADO.NET.

Chapter 12: Windows Forms.

Chapter 13: Creating Windows Controls.

Chapter 14: Web Forms.

Chapter 15: Creating Web Controls.

Chapter 16: Data Binding.

Chapter 17: Working with Classic COM and Interfaces.

Chapter 18: Component Services.

Chapter 19: Threading.

Chapter 20: Remoting.

Chapter 21: Windows Services.

Chapter 22: Web Services.

Chapter 23: VB.NET and the Internet.

Chapter 24: Security in the .NET Framework.

Chapter 25: Assemblies and Deployment.

Appendix A: Using the Visual Basic Compatibility Library.

Code Download for Professional VB.NET 2nd Edition
ChapterPageDetailsDatePrint Run
0Use of Imports System

If you're not using Visual Studio .NET (any edition) to run the examples in the book you'll need to include Imports statements within your code. See page 261 for details about the Imports statement. At the very least, you'll need to import the System namespace for every example:

Imports System

241Adding an Event Handler
If you haven't included an Imports System.Windows.Forms statement you will need to fully-qualify the calls to the MessageBoxbuttons MessageBoxIcon enumerations:
System.Windows.Forms.MessageBox.Show("Hello World", _
    "A First Look at VB.NET", _
    System.Windows.Forms.MessageBoxButtons.OK, _

58Better Support for Versioning

The version number of an assembly takes the form: Major.Minor.Build.Revision, not Major.Minor.Revision.Build.


60Cyclical References
The sentence, "Next we explicitly set objA and objA to Nothing, ???" in the penultimate paragraph should read "Next we explicitly set objA and objB to Nothing, ???"

364Use Console.WriteLine instead of Debug.WriteLine

The example programs on pages 64 - 66 use Debug.WriteLine to print statements instead of Console.WriteLine. In each case the call to Debug.WriteLine should be replaced with a call to Console.WriteLine, in order for the statements to be printed to the command line.



The final sentence of the first paragraph should read, "Consider the following code, which uses the System.Text.StringBuilder class:"



The final paragraph on this page should refer to Singles, not Shorts - as reflected in the code.


88Performing Explicit Conversions

The first line of code on this page should check if lngLong is less than Short.MaxValue rather than greater than:

If lngLong < Short.MaxValue Then

490Option Strict not Object Strict

The final paragraph on this page refers to "Object Strict". It should refer to "Option Strict".


102Passing ByValue

The 4th bullet in the summary should read, "Beware that parameters are passed ByValue by default so changes are not returned."


139The IDisposable Interface

The final two lines of code on this page contain parantheses that break the code. The code should read:

CType(mobjPerson, IDisposable).Dispose()

mobjPerson = Nothing

142Method Signatures

The final paragraph of the Method Signatures section states that the ByRef and ByVal modifiers can be used to create distinct method signatures. This is incorrect. ByVal and ByRef cannot be used as a differentiating feature when overloading a property or procedure.

02-Jul-02 1

162Creating a Base Class

mdtBirthDate should be declared as a Date, not a String:

Private mdtBirthDate As Date

167Overloading Methods

The code that checks if a key is present in the HashTable should read:

If mcolNames.ContainsKey(Type) Then mcolNames.Item(Type) = Value Else

177Checking if a key exists in the HashTable

The code that checks if a key is present in the HashTable should read:

If mcolNames.ContainsKey(Type) Then mcolNames.Item(Type) = Value Else

190The Me Keyword

The 2nd paragraph on this page should read, "..., we also need to comment out the lines that refer to the OfficeNumber property, ..."


6191The MyBase Keyword

The MyBase keyword cannot be used to invoke a Friend element from the parent class if the parent class is in a different assembly.


196Checking if a key exists in the HashTable

The code that checks if a key exists in the HashTable should read:

>If mcolNames.ContainsKey(Type) Then
    mcolNames.Item(Type) = Value

214Implementing IPrintableObject

The final paragraph on this page should read, "We can then move on to implement the other two elements defined..."


215Reusing Common Implementation

The third paragraph of the Reusing Common Implementation section should read, "..., our Value method is linked to IPrintableObject.Value using this clause:"


232Selecting the Add Reference menu option

The first paragraph on this page should read, "... Do this by clicking on the project name in the Solution Explorer window and..."


244Implementing IPrintableObject

The method declaration for PrintPage() should include an underscore character at the end of the second line top indicate that the declaration continues onto the next line:

ByVal ev As System.Drawing.Printing.PrintPageEventArgs) _

256Adding a Reference

The fourth paragraph should read, "... Selecting the Microsoft Visual Basic.NET Compatability Runtime component..."


289Writing to Trace Files

In order to use the example code on page 289 you will need to import System.IO, by adding a Imports System.IO statement to your code. In addition, so that the code will run even if the C:\mytext.txt file does not exist the first statement in the LoggingExample2() sub should read:

Dim objWriter As New IO.StreamWriter("c:\mytext.txt", True)

303Misspelling of "prescription"

Please not that "prescription" is misspelt as "presciption" several times in the example code in this chapter.

17-Oct-02 1

308Code for managing the XML stream

The first line of code on this page should read:

Dim prescriptionTextWriter As XmlTextWriter = Nothing

10334ADO.NET and XML

The final sentence of the first paragraph on this page should read, "An example code snippet that uses the GetXml method is as follows:". The code is presented as a snippet only and so is not included in the code download for the book.


341Corrupted XML

The XML shown on this page should read:

<xs:element name="Authors">
<xs:element name="au_id" type="xs:string" minOccurs="0" />
<xs:element name="au_lname" type="xs:string" minOccurs="0" />
<xs:element name="au_fname" type="xs:string" minOccurs="0" />
<xs:element name="phone" type="xs:string" minOccurs="0" />
<xs:element name="address" type="xs:string" minOccurs="0" />
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="state" type="xs:string" minOccurs="0" />
<xs:element name="zip" type="xs:string" minOccurs="0" />
<xs:element name="contract" type="xs:boolean" minOccurs="0" />

353Command Object

Please note that the code on this page is extracted from the TraverseDataReader method on the following page. You'll need to wait until page 354 to find the complete code necessary to run the example demonstrating the Command object.

17-Oct-02 1

366Stored Procedures

In response to reader feedback some clarification about stored procedures is required. The book states stored procedures are compiled prior to execution. In fact, a stored procedure in SQL Server 7 and 2000 is compiled at execution time, just like any other T-SQL statement. The execution plan of the SQL statement is cached and SQL Server uses algorithms to reuse these execution plans efficiently.

[You can find more information about stored procedures in SQL Server in the Stored Procedures and Execution Plans section of SQL Server Books Online.]

17-Oct-02 1

409The Validating Event

The code that checks if the password is blank should read:

If passwordTextbox.Text = " Then
  MessageBox.Show("Password cannot be blank")
End If

13442Setting a default value - Clarification

Using a <DefaultValue> attribute will allow designers (such as Visual Studio .NET) to set the property to a default value but please note that your property still needs to be set to an intitial value in code so that it can be used outside of such designers.


13447DefaultMaxSelectedItems() Method
The DefaultMaxSelectedItems() method is missing a line continuation character ('_'). The code should read:
Private Function DefaultMaxSelectedItems() As Integer
  Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me) ("MaxItemsSelected").Attributes
  Dim myAttribute As DefaultValueAttribute = _
    CType(attributes(GetType(DefaultValueAttribute)), _
  Return CInt(myAttribute.Value)
End Function


The first paragraph refers to CheckedListBox1; it should refer to LimitedCheckedListBox1.


460The OnPaint Method method of the Control base class

The first line of the OnPaint() method code should read:

Protected Overrides Sub OnPaint( _

491Postback Versus Non-Postback Events

The first line on this page should read, "Client-side events are automatically processed in the client browser without making a round trip to the server. So, for..."


525Reusing Code in a Web User Control

This page incorrectly states that you cannot use a @OutputCache directive in a Web User Control, when in fact you can.


528Exposing Custom Properties

Note that you will need to alter the code for the table element of the navigation bar in order to use the BackColor custom property

<table id="tblNavBar" bgcolor="<%=BackColor%>" width="100%" height="100%" style="FONT-SIZE:10pt;FONT-FAMILY:verdana">
17-Oct-02 1

561Saving Changes

The menuSaveChanges_Click method is missing a Handles statement. It should read:

Private Sub menuSaveChanges_Click( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles menuSaveChanges.Click
17-Jul-02 1

16564Corrected Stored Procedure

The thirds stored procedure on this page has a spelling mistake (sp_exectsql instead of sp_executesql) and doesn't declare the third parameter. It should read: exec sp_executesql N'UPDATE authors SET city=@p1, state=@p2 WHERE au_id=@p3, N'@p1 varchar(10), @p2 char(2), @p3 varchar(11), @p1 = 'Scottsdale', @p2 = 'AZ', @p3 = '238-95-7766'


579Saving Changes

The code for the ColumnChanged() event handler should be:



The comments in the code on this page include some dots where there should be double-quote marks. The correct comment is:

Set myObj = New MyObj ' or Set myObj = CreateObject ("MyLibrary.MyObject")

698Viewing WSDL

The first line of the final paragraph on this page should read, "To test this out, take the HTTP URL and add ?WSDL on to the end."


24836Building an assembly with a strong name

The screenshot and instructions on page 836 for adding a strong name are incorrect. In the final release of Visual Studio .NET 2002 the Strong Name tab in the Common Properties section of the Property Pages dialog has been removed.

Instead, you should use the AssemblyKeyFile attribute in an Assembly Information File, as described here.



The SendKeys class has been moved to the System.Windows.Forms namespace not the System.IO namespace.