Skip to main content

Beginning VB.NET, 2nd Edition

Beginning VB.NET, 2nd Edition

Richard Blair, Jonathan Crossland, Matthew Reynolds, Thearon Willis

ISBN: 978-0-764-54384-5

Aug 2002

888 pages

Select type: Paperback

Product not available for purchase


What is this book about?

Visual Basic .NET is the latest version of the most widely used programming language in the world, popular with professional developers and complete beginners alike. This book will teach you Visual Basic .NET from first principles. You'll quickly and easily learn how to write Visual Basic .NET code and create attractive windows and forms for the users of your applications. To get you started on the road to professional development, you'll also learn about object-oriented programming, creating your own controls, working with databases, creating menus, and working with graphics.

This second edition has been thoroughly tested on the full release version of .NET. The book is written in the proven Wrox beginning style with clear explanations and plenty of code samples. Every new concept is explained thoroughly with Try It Out examples and there are end-of-chapter questions to test yourself.

What does this book cover?

In this book, you will learn how to

  • Install Visual Basic .NET
  • Write Visual Basic .NET code
  • Understand what the .NET Framework is and why it's important
  • Control the flow through your application with loops and branching structures
  • Create useful windows and screens
  • Create your own menus
  • Gain a complete understanding of object-oriented programming
  • Work with graphics
  • Create your own controls
  • Access databases with ADO.NET
  • Create applications for the Web

Who is this book for?
This book is aimed at readers who wish to learn to program using Visual Basic .NET. It assumes you have no prior experience of programming, but moves at a fast enough pace to be interesting if you have programmed in another language.


Chapter 1: Welcome to Visual Basic .NET.

Chapter 2. Writing Software.

Chapter 3. Controlling the Flow.

Chapter 4. Building Objects.

Chapter 5. The Microsoft .NET Framework.

Chapter 6. Working with Data Structures.

Chapter 7. Building Windows Applications.

Chapter 8. Displaying Dialog Boxes.

Chapter 9. Creating Menus.

Chapter 10. Advanced Object-Oriented Techniques.

Chapter 11. Debugging and Error Handling.

Chapter 12. Building Class Libraries.

Chapter 13. Creating Your Own Custom Controls.

Chapter 14. Programming Custom Graphics.

Chapter 15. Accessing Databases.

Chapter 16. Database Programming with SQL Server and ADO.NET.

Chapter 17. Web Forms.

Chapter 18. Visual Basic .NET and XML.

Chapter 19. Web Services.

Appendix A. Where to Now?

Appendix B. Exercise Answers.


Code for Beginning VB.NET 2nd Edition
ChapterPageDetailsDatePrint Run
17Missing Chapter 17 Code
You can find the code for DataGrid Sorting in the code download section of the 3rd edition, ISBN 0764556584.

2IIS 5 and ASP.NET
On page 2 it states that chapters 17 and 19 rely on technology so you will need IIS 5.0.
As mentioned in the book itself, IIS 5.0 and above is required to deploy the ASP.NET based solutions. The default configuration of IIS 5.0 only supports ASP 3.0, but when you install Visual Studio.NET on your machine, the .NET framework updates the IIS 5.0 so that it can be used to deploy ASP.NET based solutions.
You can easily go ahead with IIS 5.0 for your ASP.NET based solution; the only thing you need to install on your web server is the latest version of Microsoft .NET Framework.

34Error in code
The code as written gives a swigley blue line error under the last underscore and "HelloUser Message". To correct this, omit the last underscore and the "HelloUser Message". It should look like the diagram on page 36.

782 Byte Strings

Where we define each character in a string as being a byte (8 bits) long, it should be 2 bytes (16 bits long).


80"27" as a String

Assigning "27" to a string takes up 4 bytes of memory because in .NET each character is 2 bytes long.


155Storing State

Under the Storing State section, in the second paragraph, last sentence, swap "to" and "do" around so the text says
"We'll see how to do this in a moment."


303Possible Bug with AcceptButton Property

According to the Microsoft documentation, "On any Windows Form you can designate a Button control to be the accept button, also known as the default button. Whenever the user presses the ENTER key, the default button is clicked regardless of which other control on the form has the focus. (The exceptions to this are when the control with focus is another button ??? in that case, the button with the focus will be clicked ??? or a multiline text box, or a custom control that traps the ENTER key.)" However, this does not appear to be the case. Setting the AcceptButton property in step 7 of the Try It Out does not seem to override the focus as it should. If the tab order is set such that the LinkLabel control has the focus when the About form is loaded, pressing ENTER opens the link rather than mimicking a click on the OK button.



Replace "strFile" with "fileName" in the ProcessFile procedure:

myReader = File.OpenText(fileName)

474Code Inconsistent

How It Works code is inconsistent with the Try It Out, so replace:
strLine with currentLine
objReader.ReadLine with myReader.ReadLine
intLineCount with lineCounter
strData with currentData



In the foreground box, the text should read "whitespace" instead of "writespace".


500Answers to Questions

The answers to the chapter 12 questions on page 500 appear under the Chapter 13 heading on page 833.



Step 1, UserControl1.vb should read MyControl.vb



Step 5, My First Control should read MyControl



Try It Out heading and step 1, UserControl1.vb should read MyControl.vb



Step 4, MyControl1 should read MyControl



Raising Events step 1, UserControl1.vb should read MyControl.vb
Consuming Events step 1, Control Test should read MyControl



Step 2, MyControl1.Reset should read MyControl.Reset


515Public Class FileButton

Remove <AttributeUsageAttribute(AttributeTargets.All)> from the first line of code in bullet 1 of the Try It Out so it becomes:

Public Class FileButton

516Change in text

Ignore the first paragraph of the How It Works ??? this explanation refers to code that is no longer shown. Remove the first line of the second paragraph, and start the paragraph:
"Our original control was derived from???"


534Answers to Questions

The answers to the chapter 13 questions on page 534 appear under the Chapter 14 heading on page 834.


586Checking Image Height

The second IF statement replaces an ELSE. With the IF instead of the ELSE, the height will now be checked, even if the image width is greater than the available space and has to be resized.

If imageWidth > clientRectangle.Width Then
      imageWidth = clientRectangle.Width
      imageHeight = CType(CType(imageWidth,
                          Double) * ratio, Integer)
   End If
   If imageHeight > clientRectangle.Height Then
      imageHeight = clientRectangle.Height
      imageWidth = CType(CType(imageHeight,
                         Double) / ratio, Integer)
   End If

589Answers to the Questions

The answers to the chapter 14 questions on page 589 appear under the Chapter 12 heading on page 832.


672objCommand.Parameters.Add("@price", txtPrice.Text)

In part 1 of the Try It Out, change the line of code shown above so that it reads:

objCommand.Parameters.Add("@price", txtPrice.Text).DbType = DbType.Currency

17681Bug Affecting ASP.NET Code

Some readers may find that having Simple File Sharing enabled when running on Windows XP Professional can cause security problems that affect how ASP.NET code operates (in particular, issues with IIS and server controls).

Such readers should ensure that they have installed the latest service packs and that Simple File Sharing is disabled.

See MSDN Knowledge Base Article Q315158, "BUG: ASP.NET Does Not Work with the Default ASPNET Account on a Domain Controller", for more details.


823Exit Do

Under the answer for chapter 3, question 4, to exit a Do???Loop we use the command Exit Do and not Exit Loop.


This book will show you:
  • How to get up and running with the Visual Basic .NET or Visual Studio .NET IDE
  • How to write Visual Basic .NET code
  • What the .NET Framework is and why it is important
  • How to use loops and branching structures so that your programs can make decisions
  • How to use menus, toolbars, dialog boxes, and other controls in your Windows programs
  • What object-oriented programming is, and what it means to you.
  • How to create re-usable class libraries and user controls