Skip to main content

Mastering Visual Basic .NET

Mastering Visual Basic .NET

Evangelos Petroutsos

ISBN: 978-0-782-12877-2

Jan 2002

1184 pages

Select type: Paperback

Product not available for purchase


VB Programmers: Get in Step with .NET

With the introduction of Visual Basic .NET, VB transcends its traditional second-class status to become a full-fledged citizen of the object-oriented programming, letting you access the full power of the Windows platform for the first time. Written bythe author of the best-selling Mastering Visual Basic 6 this all-new edition is the resource you need to make a successful transition to .NET. Comprising in-depth explanations, practical examples, and handy reference information, its coverage includes:

  • Mastering the new Windows Forms Designer and controls
  • Building dynamic forms
  • Using powerful Framework classes such as ArrayLists and HashTables
  • Persisting objects to disk files
  • Handling graphics and printing
  • Achieving robustness via structured exception handling and debugging
  • Developing your own classes and extending existing ones via inheritance
  • Building custom Windows controls
  • Building menus and list controls with custom-drawn items
  • Using ADO.NET to build disconnected, distributed applications
  • Using SQL queries and stored procedures with ADO.NET
  • Facilitating database programming with the visual database tools
  • Building web applications with ASP.NET and the rich web controls
  • Designing web applications to access databases
  • Using the DataGrid and DataList web controls
  • Building XML web services to use with Windows and web applications
  • Special topics like the Multiple Document Interface and powerful recursive programming techniques

Note: CD-ROM/DVD and other supplementary materials are not included as part of eBook file.


Part I: The Fundamentals.

Chapter 1: Getting Started with VB.NET.

Chapter 2: Visual Basic Projects.

Chapter 3: Visual Basic: The Language.

Chapter 4: Writing and Using Procedures.

Chapter 5: Working with Forms.

Chapter 6: Basic Windows Controls.

Chapter 7: More Windows Controls.

Part II: Rolling Your Own Objects.

Chapter 8: Building Custom Classes.

Chapter 9: Building Custom Windows Controls.

Chapter 10: Automating Microsoft Office Applications.

Part III: Basic Framework Classes.

Chapter 11: Storing Data in Collections.

Chapter 12: Handling Strings, Characters, and Dates.

Chapter 13: Working with Folders and Files.

Part IV: Intermediate Programming.

Chapter 14: Drawing and Painting with Visual Basic.

Chapter 15: Printing with VB.NET.

Chapter 16: The TreeView and ListView Controls.

Chapter 17: Error Handling and Debugging.

Chapter 18: Recursive Programming.

Chapter 19: The Multiple Document Interface.

Part V: Database Programming with VB.NET.

Chapter 20: Databases: Architecture and Basic Concepts.

Chapter 21: Building Database Applications with ADO.NET.

Chapter 22: Programming the ADO.NET Objects.

Part VI: VB.NET on the Web.

Chapter 23: Introduction to Web Programming.

Chapter 24: Accessing Data on the Web.

Chapter 25: XML Web Services.


Tutorial 1: Writing Multithreaded Applications iwth VB.NET
Tutorial 2: The Validation Project - Using the ErrorProvider Control
Tutorial 3: The ImageExplorer Project - Using the TreeView and ListView Controls
Download Treeview app and Project Files
Download a .zip file with the project files used in the book.
To uncompress the file, Windows users can use Windows built-in ZIP utilities or a 3rd party utility like WinZip or WinRAR. Macintosh users can simply double-click the downloaded file to extract using the built-in archive utility.
ZIP file containing projects from Chapter 9
ZIP file containing projects from Chapter 10
ZIP file containing projects from Chapter 19
Zip file containing updated My Contacts from Chapter 5
ZIP file containing the Matrix project
ChapterPageDetailsDatePrint Run
Combined Errata

Page 0 CD

Contact example from the CD Chapter 5 has an error. .
Oops, there's an error indeed.

The following statement in the SaveContact() subroutine:
contact = CType(MyContacts.Item(currentContact), Contact)

had to be changed to:

If Not adding Then

contact = CType(MyContacts.Item(currentContact), Contact)

End If

Download the updated Zip file containing My Contacts from Chapter 5 at:,typeCd-DOWNLOAD.html

Page 100

In the Code Listing, 3.4, An error is generated.
.Chars is not a member of .Char

Line as Written
If Not system.Char.Chars(i).IsLetterOrDigit(password.Chars(i)) Then

Should Read
If Not System.Char.IsLetterOrDigit(password.Chars(i)) Then

Page 121

3rd Paragraph, 4th line reads State.Intederminate , should be State.Indeterminate

Page 202

Third paragraph, 1st sentence right should be left

3rd paragraph, 4th sentence, left should be right

Page 208

Last paragraph, is incorrect.
The Startup object doesn't change when you change its name in the Solution Explorer,
which is the form's file name. If you change the form's name in the Property
Browser, you must change the project's properties.

Page 272

Listing 6.12, Please replace the listing with the following:
Private Sub bttnMoveDest_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles bttnMoveDest.Click

While sourceList.SelectedIndices.Count > 0
End While
End Sub

Page 376

Line 12 of Listing 8.38:
Please change:
perim = Perimeter()
perim = Perimeter() / 2

Page 426

Section "Designing Owner-Drawn ListBox Controls",
The code discussed in the book will work, but you can find a better implementation of the owner-drawn ListBox control in the code posted here. The project is the OwnerDrawnList project and it contains a README.TXT file that describes the changes.

Page 436

I am getting the error "wordapp.quit()" :
***Please see "downloads section" for updated CH 10 files.

This issue was introduced in one of the pre-release versions of Visual Studio and the solution is to replace the statement:


with the following:

Actually, I was aware of this bug, but I was expecting it would be fixed by
the final release. I guess it's too late to correct the Office object model
and we'll have to live with this (inelegant) workaround.

I have revised the projects of chapter 10 and I'm attaching a ZIP file with the latest version of the projects. The affected projects contain a
README.TXT file that describes the workaround in detail.

April 1, 2002



The original application (as discussed in the book),calls the Document.Close method to close an open document and the Application.Quit method to terminate Word. However, you can't call these methods directly - if you do, an exception
will be raised, because these two method names are not unique in their namespace.

To close a document, convert the Document object
that represents an open document to the Word._Document type and then call the Close method:

CType(thisDoc, Word._Document).Close(Word.WdSaveOptions.wdDoNotSaveChanges)

To close Word, convert the Word.Application object
that represents the running application to the
Word._Application type and then call its Quit method:


The argument passed to both methods indicates that Word shouldn't prompt the user to saving the changes. You can also call these methods passing False as argument.

The changes affect the statements that close an open document and terminate the Word application. It's critical that you close any documents you no longer need and shut down the running instance of Word. If not, you'll get an exception when you attempt to open the same document again. Listing in the middle of the page: Please replace the statement: WordApp.Quit() to CType(WordApp, Word._Application).Quit()

Page 439

Please change the second to last line of the listing from:

CType(WordApp, Word._Application).Quit()

Author note:

I have revised all the projects of chapter 10 and you can find the revised projects in the file CH10.ZIP in the DownLoad section of the book's pages on this site.

Page 481

Please change the following statement in the middle of the page:

System.Array.Sort(arrayName, startIndex, endIndex)
System.Array.Sort(arrayName, startIndex, count)

The sentence following the previous statement on the same page should be changed to:

"where startIndex is the starting index of the section of the array to be sorted and count is the number of elements to be sorted. This method will sort count elements starting with the element at index startIndex."

Page 508

Stacks and Queues. .
In the short discussion of Stacks and Queues in the second paragraph of the Other Collections section, the FIFO and LIFO definitions are reversed. A stack is a LIFO structure, and a Queue is a FIFO structure. All other discussion of the collections is correct.

Page 515

The 4th line in Listing 11.14:Console.WriteLine( The value of & hEnum.Key & {0} is & hEnum.Value) should be: Console.WriteLine( The value of & hEnum.Key & is {0} , hEnum.Value)

Page 543

The following statement in the code sample: Dim vbTab As String = vbCrLf should be: Dim vbTab As String = vbTab

Page 564

The second line after Table 12.5 states: ... will return the value 70 , it should read: ... will return the value 130

Page 640

The section's title should be: The GraphicsPath Object

Page 657

In the syntax of the MeasureString method the last two arguments should be reversed:
The following statement that appears in the middle of the page:
e.Graphics.MeasureString(string, Font, fitSize, StringFormat, lines, cols)
should be:
e.Graphics.MeasureString(string, Font, fitSize, StringFormat, cols, lines)

Page 758

Globe Project, The serializing of the contents does not work correctly.

The Globe control demonstrates how to populate the TreeView control and how to persist its Nodes collection to a file. The interface of the application allows the addition of nested nodes up to 3 levels. The code that saves the Nodes collection will work with any number of nesting levels (you just need a different interface to make a tree with an arbitrary nesting depth).

I've written an application that allows you to add nodes to a TreeView control at run-time and persist the control's contents to an XML file. I'm attaching a ZIP file with the project's code. The code is documented and you won't have any problems following it.


Page 943

4th paragraph
"Drop the Customers table on the form"
Two new objects will be added to your form: the SqlConnection1 object and
the SqlDataAdapter1 object.
"Rename the SqlDataAdapter1 object that will be automatically created to
Both objects will be selected, so you must click to an empty area and then
select the SqlDataAdapter1 object with the mouse. Locate the Name property
in the Property Browser and set its value to "DACustomers"
"Then configure the DataAdapter...."
The steps in configuring a DataAdapter have been described earlier in this
chapter and I've skipped the details. Basically, accept all the defaults
suggested by the wizard.

"Create the DataSet object and name it DSCustomers"
Here, I should have said "Create the DataSet object by clicking the Generate
DataSet link below the Property Browser (or by selecting the Data > Generate
DataSet command." Indeed, when you drop a DataSet from the Toolbox onto the
form, you can't rename it before you create it. However, we drop a DataSet
object onto the form only when we want to create a DataSet from scratch.
Once we've created a DataAdapter, we let Visual Studio generate the
appropriate DataSet. As soon as you click the Generate DataSet button, you
will be prompted to enter the name of the new DataSet (or select an existing
one, if the project contains a DataSet already).

Page 945

The listing in the middle of the page (Button2_Click subroutine) should be changed. Please add the following statement before the call the to Update method:

Me.BindingContext(DsCustomers1, "Customers").EndCurrentEdit

The correct listing of the subroutine is:

Private Sub Button2_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click
Me.BindingContext(DsCustomers1, "Customers").EndCurrentEdit
End Sub

Page FAQ

Chap 6 "resx" error :
Chap 6 examples using GUI -ComboboxStyles and WordFrequencies - run but have resx.input error when try to view with designer. I am using beta2-vbnet

Please delete the file with extensions RESX. To view it, click the "Show All
Files" buttons at the top of the Solution Explorer and expand the item that
corresponds to the Form. VB will create the resource file for you the next
time you run the project.