Preface |
|
xiii | |
Read This Before You Begin |
|
xviii | |
|
An Introduction to Visual Basic 2005 |
|
|
1 | (70) |
|
|
2 | (1) |
|
A Brief History of Programming Languages |
|
|
2 | (2) |
|
|
3 | (1) |
|
|
3 | (1) |
|
|
3 | (1) |
|
|
4 | (2) |
|
|
6 | (4) |
|
The Common Language Runtime |
|
|
7 | (1) |
|
Solutions, Projects, and Files |
|
|
7 | (1) |
|
Starting Microsoft Visual Studio 2005 |
|
|
8 | (2) |
|
Creating a Visual Basic 2005 Windows-Based Application |
|
|
10 | (2) |
|
Managing the Windows in the IDE |
|
|
11 | (1) |
|
The Windows Form Designer Window |
|
|
12 | (1) |
|
The Solution Explorer Window |
|
|
13 | (2) |
|
|
15 | (4) |
|
Properties of a Windows Form Object |
|
|
16 | (3) |
|
|
19 | (5) |
|
|
21 | (1) |
|
|
22 | (2) |
|
|
24 | (3) |
|
|
26 | (1) |
|
|
27 | (1) |
|
Starting and Ending an Application |
|
|
27 | (3) |
|
Using an Assignment Statement |
|
|
30 | (1) |
|
|
31 | (1) |
|
Closing the Current Solution |
|
|
32 | (1) |
|
Opening an Existing Solution |
|
|
32 | (1) |
|
Programming Tutorial: Creating a Visual Basic 2005 Application |
|
|
33 | (23) |
|
Starting Visual Studio .NET |
|
|
33 | (1) |
|
Creating a Visual Basic 2005 Windows-based Application |
|
|
34 | (1) |
|
Managing the Windows in the IDE |
|
|
35 | (1) |
|
Using the Toolbox Window to Add Objects to a Form |
|
|
36 | (4) |
|
Using the Properties Window to Change an Object's Properties |
|
|
40 | (3) |
|
|
43 | (1) |
|
Displaying an Image in a Picture Box Control |
|
|
44 | (2) |
|
Starting and Ending an Application |
|
|
46 | (3) |
|
Writing Visual Basic 2005 Code |
|
|
49 | (4) |
|
Closing the Current Solution |
|
|
53 | (1) |
|
Opening an Existing Solution |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
54 | (2) |
|
Exiting Visual Studio .NET |
|
|
56 | (1) |
|
Programming Example: State Capitals |
|
|
56 | (2) |
|
|
56 | (2) |
|
|
58 | (1) |
|
|
58 | (2) |
|
|
60 | (3) |
|
Self-Check Questions and Answers |
|
|
63 | (1) |
|
|
64 | (3) |
|
Review Exercises - Short Answer |
|
|
67 | (1) |
|
|
67 | (2) |
|
|
69 | (2) |
|
Castle's Ice Cream Parlor |
|
|
69 | (1) |
|
|
69 | (1) |
|
|
69 | (1) |
|
|
70 | (1) |
|
Creating a User Interface |
|
|
71 | (56) |
|
|
72 | (1) |
|
|
72 | (6) |
|
Identifying the Application's Tasks |
|
|
72 | (2) |
|
|
74 | (3) |
|
|
77 | (1) |
|
Designing the User Interface |
|
|
78 | (8) |
|
|
81 | (3) |
|
Including Graphics in the User Interface |
|
|
84 | (1) |
|
Including Different Fonts in the User Interface |
|
|
85 | (1) |
|
Including Color in the User Interface |
|
|
85 | (1) |
|
|
86 | (1) |
|
Setting the TabIndex Property |
|
|
87 | (3) |
|
Designating Default and Cancel Buttons |
|
|
90 | (1) |
|
Including Splash Screens and Dialog Boxes in an Application |
|
|
91 | (2) |
|
|
93 | (2) |
|
Programming Tutorial: Creating the Color Game Application |
|
|
95 | (16) |
|
Completing the MainForm's Interface |
|
|
96 | (4) |
|
|
100 | (1) |
|
Coding the Color Buttons' Click Event Procedures |
|
|
101 | (1) |
|
Coding the Clear Colors Button's Click Event Procedure |
|
|
102 | (1) |
|
Adding the DialogForm to the Color Game Project |
|
|
102 | (2) |
|
Coding the DialogForm and the Options Button |
|
|
104 | (2) |
|
Adding the SplashScreenForm to the Color Game Project |
|
|
106 | (1) |
|
Completing the Color Game Application |
|
|
107 | (4) |
|
Programming Example: Moonbucks Coffee |
|
|
111 | (4) |
|
|
112 | (1) |
|
|
112 | (1) |
|
Objects, Properties, and Settings |
|
|
113 | (1) |
|
|
114 | (1) |
|
|
115 | (1) |
|
|
115 | (2) |
|
|
117 | (1) |
|
Self-Check Questions and Answers |
|
|
118 | (1) |
|
|
119 | (2) |
|
Review Exercises - Short Answer |
|
|
121 | (1) |
|
|
122 | (2) |
|
|
124 | (3) |
|
Crispies Bagels and Bites |
|
|
124 | (1) |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
125 | (2) |
|
Variables, Constants, Methods, and Calculations |
|
|
127 | (68) |
|
|
128 | (3) |
|
Selecting a Data Type for a Variable |
|
|
128 | (2) |
|
Selecting a Name for a Variable |
|
|
130 | (1) |
|
|
131 | (1) |
|
Assigning Data to an Existing Variable |
|
|
132 | (9) |
|
Using the TryParse Method |
|
|
134 | (6) |
|
|
140 | (1) |
|
Writing Arithmetic Expressions |
|
|
141 | (3) |
|
The Scope and Lifetime of a Variable |
|
|
144 | (4) |
|
|
148 | (2) |
|
|
150 | (2) |
|
Option Explicit and Option Strict |
|
|
152 | (2) |
|
Coding the Skate-Away Sales Application |
|
|
154 | (4) |
|
Using Pseudocode to Plan a Procedure |
|
|
155 | (1) |
|
Using a Flowchart to Plan a Procedure |
|
|
156 | (2) |
|
Coding the Clearbutton's Click Event Procedure |
|
|
158 | (3) |
|
Clearing the Contents of a Control's Text Property |
|
|
159 | (1) |
|
|
160 | (1) |
|
Coding The Calcbutton's Click Event Procedure |
|
|
161 | (3) |
|
Testing and Debugging the Application |
|
|
164 | (2) |
|
Formatting Numeric Output |
|
|
166 | (4) |
|
Programming Tutorial: Creating the Change Game Application |
|
|
170 | (7) |
|
Completing the Change Game Application |
|
|
171 | (1) |
|
Coding the clearButton's Click Event Procedure |
|
|
172 | (1) |
|
Coding the calcButton's Click Event Procedure |
|
|
173 | (4) |
|
Programming Example: Currency Calculator |
|
|
177 | (4) |
|
|
178 | (1) |
|
|
178 | (1) |
|
Objects, Properties, and Settings |
|
|
179 | (1) |
|
|
180 | (1) |
|
|
180 | (1) |
|
|
180 | (1) |
|
|
181 | (2) |
|
|
183 | (1) |
|
Self-Check Questions and Answers |
|
|
184 | (2) |
|
|
186 | (2) |
|
Review Exercises - Short Answer |
|
|
188 | (1) |
|
|
189 | (4) |
|
|
193 | (2) |
|
|
193 | (1) |
|
|
193 | (1) |
|
|
193 | (1) |
|
|
193 | (2) |
|
Making Decisions in a Program |
|
|
195 | (74) |
|
|
196 | (1) |
|
Writing Pseudocode for the If and If/Else Selection Structures |
|
|
197 | (1) |
|
Flowcharting the If and If/Else Selection Structures |
|
|
198 | (1) |
|
Coding the If and If/Else Selection Structures |
|
|
199 | (1) |
|
|
200 | (9) |
|
Using Comparison Operators -- Swapping Numeric Values |
|
|
202 | (4) |
|
Using Comparison Operators -- Example 2 |
|
|
206 | (3) |
|
Using the ToUpper and ToLower Methods |
|
|
209 | (2) |
|
|
211 | (6) |
|
|
214 | (2) |
|
Using Logical Operators in an If...Then...Else Statement |
|
|
216 | (1) |
|
The String.IsNullOrempty Method |
|
|
217 | (1) |
|
Modifying the Skate-Away Sales Application |
|
|
218 | (3) |
|
The MessageBox.Show Method |
|
|
221 | (5) |
|
Nested Selection Structures |
|
|
226 | (5) |
|
The If/Elself/Else Selection Structure |
|
|
231 | (2) |
|
The Case Selection Structure |
|
|
233 | (4) |
|
Using To and Is in an ExpressionList |
|
|
235 | (2) |
|
Generating Random Integers |
|
|
237 | (2) |
|
Programming Tutorial: Creating the Rock, Paper, Scissors Game Application |
|
|
239 | (1) |
|
Creating the Rock, Paper, Scissors Game Interface |
|
|
240 | (12) |
|
Coding the Rock, Paper, Scissors Game Application |
|
|
242 | (6) |
|
Programming Example: Fat Calculator Application |
|
|
248 | (1) |
|
|
249 | (1) |
|
|
249 | (1) |
|
Objects, Properties, and Settings |
|
|
249 | (1) |
|
|
250 | (1) |
|
|
250 | (1) |
|
|
251 | (1) |
|
|
252 | (1) |
|
|
253 | (2) |
|
Self-Check Questions and Answers |
|
|
255 | (1) |
|
|
256 | (3) |
|
Review Exercises - Short Answer |
|
|
259 | (4) |
|
|
263 | (5) |
|
|
268 | (1) |
|
Allenton Water Department |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
268 | (1) |
|
Repeating Program Instructions |
|
|
269 | (80) |
|
|
270 | (1) |
|
|
270 | (4) |
|
|
274 | (7) |
|
The Monthly Payment Calculator Application |
|
|
277 | (1) |
|
Selecting the Existing Text in a Text Box |
|
|
278 | (2) |
|
Coding a Control's TextChanged Event Procedure |
|
|
280 | (1) |
|
Using a List Box in an Interface |
|
|
281 | (6) |
|
Adding Items to a List Box |
|
|
282 | (2) |
|
The SelectedItem and SelectedIndex Properties |
|
|
284 | (2) |
|
The SelectedValueChanged and SelectedIndexChanged Events |
|
|
286 | (1) |
|
Modifying the Monthly Payment Calculator Application |
|
|
287 | (3) |
|
Using a Combo Box in an Interface |
|
|
290 | (4) |
|
|
294 | (6) |
|
Using Counters and Accumulators |
|
|
300 | (2) |
|
|
300 | (2) |
|
The Sales Express Application |
|
|
302 | (5) |
|
Programming Tutorial: Creating the Car Race Game Application |
|
|
307 | (19) |
|
Completing the Car Race Game Interface |
|
|
308 | (4) |
|
Coding the Car Race Game Application |
|
|
312 | (1) |
|
Moving a Control While an Application Is Running |
|
|
313 | (2) |
|
Coding the raceTimer's Tick Event Procedure |
|
|
315 | (11) |
|
Programming Example: Grade Calculator |
|
|
326 | (4) |
|
|
326 | (1) |
|
|
327 | (1) |
|
Objects, Properties, and Settings |
|
|
327 | (1) |
|
|
328 | (1) |
|
|
328 | (1) |
|
|
329 | (1) |
|
|
330 | (2) |
|
|
332 | (1) |
|
Self-Check Questions and Answers |
|
|
333 | (2) |
|
|
335 | (3) |
|
Review Exercises - Short Answer |
|
|
338 | (2) |
|
|
340 | (7) |
|
|
347 | (2) |
|
Sonheim Manufacturing Company |
|
|
347 | (1) |
|
|
348 | (1) |
|
|
348 | (1) |
|
|
348 | (1) |
|
String Manipulation and More Controls |
|
|
349 | (82) |
|
Manipulating Strings in Visual Basic |
|
|
350 | (1) |
|
Determining the Number of Characters Contained in a String |
|
|
350 | (2) |
|
Removing Characters from a String |
|
|
352 | (6) |
|
|
356 | (2) |
|
Replacing Characters in a String |
|
|
358 | (6) |
|
|
361 | (3) |
|
Inserting Characters In a String |
|
|
364 | (6) |
|
|
368 | (2) |
|
Search a String for One or More Characters |
|
|
370 | (12) |
|
|
375 | (3) |
|
|
378 | (4) |
|
Accessing Characters Contained in a String |
|
|
382 | (3) |
|
|
385 | (8) |
|
|
388 | (5) |
|
|
393 | (6) |
|
|
393 | (3) |
|
|
396 | (3) |
|
Programming Tutorial: Hangman Game |
|
|
399 | (11) |
|
|
400 | (1) |
|
|
400 | (10) |
|
Programming Example: Glasgow Health Club Dues Calculator Application |
|
|
410 | (7) |
|
|
411 | (1) |
|
|
411 | (1) |
|
Objects, Properties, and Settings |
|
|
412 | (1) |
|
|
413 | (1) |
|
|
414 | (1) |
|
|
414 | (3) |
|
|
417 | (1) |
|
|
418 | (1) |
|
Self-Check Questions and Answers |
|
|
419 | (1) |
|
|
420 | (3) |
|
Review Exercises -- Short Answer |
|
|
423 | (1) |
|
|
424 | (5) |
|
|
429 | (2) |
|
|
429 | (1) |
|
|
430 | (1) |
|
|
430 | (1) |
|
|
430 | (1) |
|
Sub and Function Procedures |
|
|
431 | (64) |
|
|
432 | (1) |
|
|
432 | (6) |
|
The Gadis Antiques Application |
|
|
434 | (4) |
|
Including Parameters in an Independent Sub Procedure |
|
|
438 | (1) |
|
|
438 | (10) |
|
Passing Variables by Value |
|
|
439 | (5) |
|
Passing Variables by Reference |
|
|
444 | (4) |
|
Associating a Procedure with Different Objects and Events |
|
|
448 | (3) |
|
|
451 | (4) |
|
The Pine Lodge Application |
|
|
452 | (3) |
|
Programming Tutorial: Concentration Game Application |
|
|
455 | (21) |
|
|
456 | (1) |
|
Coding the Concentration Game Application |
|
|
457 | (7) |
|
Converting Object Variables |
|
|
464 | (3) |
|
Completing the Concentration Game Application |
|
|
467 | (9) |
|
Programming Example: Rainfall Application |
|
|
476 | (4) |
|
|
476 | (1) |
|
|
476 | (1) |
|
Objects, Properties, and Settings |
|
|
477 | (1) |
|
|
478 | (1) |
|
|
478 | (1) |
|
|
479 | (1) |
|
|
480 | (1) |
|
|
481 | (1) |
|
Self-Check Questions and Answers |
|
|
482 | (1) |
|
|
483 | (3) |
|
Review Exercises - Short Answer |
|
|
486 | (2) |
|
|
488 | (4) |
|
|
492 | (3) |
|
|
492 | (1) |
|
|
492 | (1) |
|
|
493 | (1) |
|
|
493 | (2) |
|
|
495 | (56) |
|
|
496 | (1) |
|
|
496 | (2) |
|
Storing Data in a One-Dimensional Array |
|
|
498 | (1) |
|
Manipulating One-Dimensional Arrays |
|
|
499 | (17) |
|
Displaying the Contents of a One-Dimensional Array |
|
|
500 | (2) |
|
The For Each...Next Statement |
|
|
502 | (1) |
|
Using the Subscript to Access an Element in a One-Dimensional Array |
|
|
503 | (2) |
|
Searching a One-Dimensional Array |
|
|
505 | (2) |
|
Calculating the Average Amount Stored in a One-Dimensional Numeric Array |
|
|
507 | (2) |
|
Determining the Highest Value Stored in a One-Dimensional Array |
|
|
509 | (2) |
|
Updating the Values Stored in a One-Dimensional Array |
|
|
511 | (2) |
|
Sorting the Data Stored in a One-Dimensional Array |
|
|
513 | (3) |
|
Parallel One-Dimensional Arrays |
|
|
516 | (3) |
|
|
519 | (6) |
|
Storing Data in a Two-Dimensional Array |
|
|
521 | (1) |
|
Searching a Two-Dimensional Array |
|
|
522 | (3) |
|
Programming Tutorial: Lottery Game Application |
|
|
525 | (5) |
|
|
525 | (1) |
|
Coding the Lottery Game Application |
|
|
525 | (5) |
|
Programming Example: Perrytown Gift Shop Application |
|
|
530 | (6) |
|
|
531 | (1) |
|
|
531 | (1) |
|
Objects, Properties, and Settings |
|
|
532 | (1) |
|
|
533 | (1) |
|
|
533 | (1) |
|
|
534 | (2) |
|
|
536 | (1) |
|
|
536 | (1) |
|
Self-Check Questions and Answers |
|
|
537 | (1) |
|
|
538 | (4) |
|
Review Exercises - Short Answer |
|
|
542 | (1) |
|
|
543 | (6) |
|
|
549 | (2) |
|
|
549 | (1) |
|
|
549 | (1) |
|
|
550 | (1) |
|
|
550 | (1) |
|
Structures and Sequential Access files |
|
|
551 | (46) |
|
|
552 | (10) |
|
Using a Structure to Declare a Variable |
|
|
553 | (1) |
|
Passing a Structure Variable to a Procedure |
|
|
554 | (5) |
|
Creating an Array of Structure Variables |
|
|
559 | (3) |
|
|
562 | (1) |
|
|
562 | (1) |
|
Writing Information to a Sequential Access File |
|
|
563 | (4) |
|
Aligning Columns of Information in a Sequential Access File |
|
|
566 | (1) |
|
Reading Information from a Sequential Access File |
|
|
567 | (3) |
|
Determining Whether a File Exists |
|
|
568 | (2) |
|
|
570 | (1) |
|
|
571 | (4) |
|
Programming Tutorial: Modified Car Race Game Application |
|
|
575 | (6) |
|
Modifying the Car Race Game Application |
|
|
576 | (5) |
|
Programming Example: Glovers Application |
|
|
581 | (5) |
|
|
582 | (1) |
|
|
582 | (1) |
|
Objects, Properties, and Settings |
|
|
582 | (1) |
|
|
583 | (1) |
|
|
583 | (1) |
|
|
584 | (2) |
|
|
586 | (1) |
|
|
586 | (1) |
|
Self-Check Questions and Answers |
|
|
587 | (1) |
|
|
588 | (2) |
|
Review Exercises - Short Answer |
|
|
590 | (2) |
|
|
592 | (3) |
|
|
595 | (2) |
|
|
595 | (1) |
|
|
595 | (1) |
|
|
595 | (1) |
|
|
595 | (2) |
|
Creating Classes and Objects |
|
|
597 | (60) |
|
|
598 | (1) |
|
|
598 | (3) |
|
Example 1---Using a Class That Contains Public Variables Only |
|
|
601 | (3) |
|
Example 2---Using a Class That Contains a Private Variable, a Property Procedure, and Two Methods |
|
|
604 | (8) |
|
|
608 | (1) |
|
Methods Other Than Constructors |
|
|
609 | (3) |
|
Example 3---Using a Class That Contains Two Constructors |
|
|
612 | (5) |
|
Example 4---Using a Class That Contains Overloaded Methods |
|
|
617 | (5) |
|
Example 5---Using a Base Class and a Derived Class |
|
|
622 | (4) |
|
Programming Tutorial: Card Game |
|
|
626 | (12) |
|
|
627 | (1) |
|
Coding the Card Game Application |
|
|
627 | (11) |
|
Programming Example: Kessler Landscaping Application |
|
|
638 | (4) |
|
|
639 | (1) |
|
|
639 | (1) |
|
|
639 | (1) |
|
Code (MyRectangle.vb file) |
|
|
640 | (1) |
|
|
641 | (1) |
|
|
642 | (1) |
|
|
643 | (1) |
|
Self-Check Questions and Answers |
|
|
644 | (1) |
|
|
645 | (2) |
|
Review Exercises -- Short Answer |
|
|
647 | (2) |
|
|
649 | (5) |
|
|
654 | (3) |
|
|
654 | (1) |
|
|
655 | (1) |
|
|
655 | (1) |
|
|
655 | (2) |
|
|
657 | (50) |
|
|
658 | (2) |
|
|
660 | (1) |
|
Connecting a Database to an Application |
|
|
661 | (3) |
|
Previewing the Data Contained in a Dataset |
|
|
662 | (2) |
|
Binding the Objects in a Dataset |
|
|
664 | (8) |
|
Having the Computer Create a Bound Control |
|
|
664 | (6) |
|
Binding to an Existing Control |
|
|
670 | (2) |
|
Accessing the Records in a Dataset |
|
|
672 | (2) |
|
|
674 | (10) |
|
|
678 | (2) |
|
Using the Query Builder Dialog Box |
|
|
680 | (1) |
|
Allowing the User to Run a Query |
|
|
681 | (3) |
|
Programming Tutorial: Trivia Game Application |
|
|
684 | (10) |
|
|
685 | (1) |
|
Coding the Trivia Game Application |
|
|
685 | (9) |
|
Programming Example: Cartwright Industries Application |
|
|
694 | (3) |
|
|
695 | (1) |
|
User Interface (drag the table to the form) |
|
|
695 | (1) |
|
Objects, Properties, and Settings |
|
|
696 | (1) |
|
|
696 | (1) |
|
|
697 | (1) |
|
|
698 | (1) |
|
Self-Check Questions and Answers |
|
|
699 | (1) |
|
|
700 | (2) |
|
Review Exercises -- Short Answer |
|
|
702 | (1) |
|
|
703 | (2) |
|
|
705 | (2) |
|
|
705 | (1) |
|
|
705 | (1) |
|
|
705 | (1) |
|
|
706 | (1) |
Appendix A How To Boxes |
|
707 | (4) |
Appendix B GUI Design Rules |
|
711 | (4) |
Appendix C Visual Basic Type Conversion Functions |
|
715 | (2) |
Appendix D Creating a SQL Server Database |
|
717 | (6) |
Glossary |
|
723 | (10) |
Index |
|
733 | |