Visual Basic 6 Programming
by Peter G. Aitken
Published by The Coriolis Group, August 1998.
700 pages, $49.99
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.
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 Codes 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
At the top of the page, the second line should read:
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.
I erroneously state that variable length strings cannot be used in a structure. In fact they can be used like any other data type.
At the top of the page. the second line of code should be Next Count and not Next X.
In Listing 5-4 change
The DisplayResult procedure expects a type Double argument but was being passed a type string, which would cause a Type Mismatch error.
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.
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
txtDisplay.Text = ""
Last line of code on the page should read
S = "abc" & MyVariant & "def"
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 <>
NewEntry = True
DisplayHasData = True
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)
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)
Last line, "flagsare" should read "flags are".
In Listing 5.11 the call to DisplayValue() should be to DisplayResult().
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.
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.
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.