vb6bb_cover.jpg (12592 bytes)

Visual Basic 6 Programming

Blue Book

by Peter G. Aitken

Published by The Coriolis Group, August 1998.
700 pages, $49.99
Includes CD-ROM
ISBN 1-57610-281-5

This book is a revision and update of my popular book Visual Basic 5 Programming Explorer. It has been extensively revised to cover the new and improved technologies in Visual Basic version 6, including ActiveX Data Objects, Internet programming, and component creation. The book follows a "learn by doing" approach where you learn Visual Basic programming skills by creating a series of real-world programs. It is intended for beginning to intermediate level programmers.

The author, Peter G. Aitken, is a widely known writer with over 25 computer-related books to his credit. His titles include Teach Yourself C in 21 Days, The Visual Basic Insider, and Teach Yourself Visual Basic 6 Internet Programming in 21 Days. For many years Peter wrote the popular Basically Visual column for Visual Developer Magazine.

Order from Amazon.Com

Email the author

Table of Contents

Section 1: Programming the Visual Basic Way

Chapter 1. RAD, Baby.
Chapter 2. Visual Basic for Intelligent Folks.
Chapter 3. Drawing Your Way to Success.
Chapter 4. The Code’s the Thing.
Chapter 5. Visual Design + Basic Code = Visual Basic.

Section 2: Sharing Data and Code

Chapter 6. Component Madness.
Chapter 7. Objects and Classes.
Chapter 8. Creating an ActiveX Component.
Chapter 9. Dynamic Data Exchange.
Chapter 10. Object Linking and Embedding.

Section 3: Making Things Happen

Chapter 11. Working With Text.
Chapter 12. Graphics.
Chapter 13. File Access.
Chapter 14. File and Folder Management.
Chapter 15. Serial Communication.
Chapter 16. Multimedia Magic.

Section 4: Programming for the Internet

Chapter 17. Creating and Using ActiveX Controls.
Chapter 18. Using the Internet-Related Controls.

Section 5: Database Programming

Chapter 19. Database Basics.
Chapter 20. Alphabet Soup: ODBC, DAO, and More.
Chapter 21. Database Design and Tools.
Chapter 22. Designing the Database Application.
Chapter 23. Validation Code and the Invoices Form.
Chapter 24. Client/Server Database Programming.

Section 6: Final Touches

Chapter 25. Error Handling.
Chapter 26. Debugging and Distributing Your Programs.
Chapter 27. Accessing the Windows API.

Back to main Visual Basic page


Page 55

At the top of the page, the second line should read:

Caption: B&igger

This makes the "i" the shortcut key for this Command Button rather than the "B" which would conflict with the shortcut key for the Blue option button.

Page 71

I erroneously state that variable length strings cannot be used in a structure. In fact they can be used like any other data type.

Page 89

At the top of the page. the second line of code should be Next Count and not Next X.

Page 113

In Listing 5-4 change 

DisplayResult (txtDisplay.Text)


DisplayResult (CDbl(txtDisplay.Text))

 The DisplayResult procedure expects a type Double argument but was being passed a type string, which would cause a Type Mismatch error.

Page 114

First line of code reads

txtDisplay.Text = "-" & txtDisplay

and should read

txtDisplay.Text = "-" & txtDisplay.Text

The original code runs OK because Text is the default property of the Text Box control, but specifying the property is preferred for clarity's sake.

Page 115

In Listing 5.8 the code for the cmdDecimal button's Click procedure lacks the code to put the value on the stack. The following code should be added to the procedure, at the beginning:

If NewEntry Then
   NewEntry = False
   If DisplayHasData Then
      StackPointer = StackPointer + 1
      Stack(StackPointer) = txtDisplay.Text
   End If
   txtDisplay.Text = ""
End If

Page 97

Last line of code on the page should read

S = "abc" & MyVariant & "def"

Page 113

Listing 5.4 does not work properly if the display is empty - in other words, if the user clicks Enter without entering a number. This can be corrected by replacing the last 3 lines of code with the following:

If txtDisplay.Text <> "" Then
   NewEntry = True
   DisplayHasData = True
End If

Page 120

The Visual Basic trigonomteric functions expect angles to be expressed in radians, not the more commonly used degrees. As written the code will give correct answers for Sin, Cos, and Tan only if you enter radian values. To convert degrees to radians multiply by pi/180 (where pi = 3.1415926535897932). To change the program to work with degrees, the code in listing 5.10 will look like this:

Select Case Index
    Case 0 ' Sin
        Result = Sin(TextDisplay.Text * 3.1415926535897932 / 180)
    Case 1 ' Cos
        Result = Cos(TextDisplay.Text * 3.1415926535897932 / 180)
    Case 2 ' Tan
        Result = Result = Tan(TextDisplay.Text * 3.1415926535897932 / 180)
End Select

Good programming practice would define a constant PI for use here:

Const PI = 3.1415926535897932


Select Case Index
    Case 0 ' Sin
        Result = Sin(TextDisplay.Text * PI / 180)
    Case 1 ' Cos
        Result = Cos(TextDisplay.Text * PI / 180)
    Case 2 ' Tan
        Result = Result = Tan(TextDisplay.Text * PI / 180)
End Select

Page 121

Last line, "flagsare" should read "flags are".

Page 122

In Listing 5.11 the call to DisplayValue() should be to DisplayResult().

Page 146

In the Superstring class, a read pointer out that if the Insert method is called twice in a row you will get erroneous results because the mVarLength property is not updated in that method. To prevent this, add the line

mVarLength = Len(mVarValue)

as the last line of code in the Insert method.

Page 150

I forgot to mention that the Value property should be made the default property of the SuperString class, otherwise the code on this page will not work. You need to change

SS1 = txtOriginal.Text


SS1.Value = txtOriginal.Text

and also change

txtResult.Text = SS1


txtResult.Text = SS1.Value

With these change the code will work regardless of whether Value is the default property.


Page 161

Several readers have reported problems running the demonstration project for the TreeView control. The problem is apparently caused when the module MSCOMCTL.OCX cannot be loaded along with the project. For reasons I do not understand, this causes the TreeView control named TV1 and the ListImage control named ListImage1 in the project to be replaced with PictureBox controls. As a result the program will not work. Here's how to fix it.

1. Open the project.

2. Delete the control TV1 and the control ListImage1 from the form.

3. Press Ctrl+T to display the Components dialog box.

4. Select the Microsoft Windows Common Controls 6.0 enter then close the dialog box. You'll now have several more control icons in your toolbox.

5. Add a Treeview control to the form and change its Name property to TV1.

6. Add an ImageList control to the form and leave its properties at the default values.

The program should now run properly.