Skip Navigation LinksLearn-Visual-Basic-A-Colleges-Prep-Tutorial-Table-of-Contents

Learn Visual Basic

A College Prep Tutorial

Table of Contents

 

1. Introduction to the Visual Basic Environment

Preview 1-1

Course Objectives 1-2

What is Visual Basic? 1-3

Visual Basic vs. Visual Basic .NET vs. Visual Basic 6.0 1-5

A Brief Look at Object-Oriented Programming (OOP) 1-6

Structure of a Visual Basic Windows Application 1-7

Steps in Developing a Windows Application 1-9

Starting Visual Basic 1-10

Visual Basic Integrated Development Environment (IDE) 1-12

Saving a Visual Basic Project 1-20

Drawing the User Interface 1-21

Example 1-1: Stopwatch Application - Drawing Controls 1-24

Opening a Saved Visual Basic Project 1-25

Setting Properties of Controls at Design Time 1-27

Setting Properties at Run Time 1-30

How Names Are Used in Control Events 1-31

Use of Form Name Property 1-32

Example 1-2: Stopwatch Application - Setting Properties 1-34

Writing Code 1-36

Variables 1-40

Visual Basic Data Types 1-41

Variable Declaration 1-43

Arrays 1-46

Constants 1-48

Variable Initialization 1-49

Intellisense Feature 1-50

Example 1-3: Stopwatch Application - Writing Code 1-51

1. Introduction to the Visual Basic Environment (cont.)

Class Review 1-55

Practice Problems 1 1-56

Problem 1-1. Beep Problem

Problem 1-2. Caption Problem

Problem 1-3. Enabled Problem

Problem 1-4. Date Problem

Exercise 1: Calendar/Time Display 1-57

 

2. The Visual Basic Language

Review and Preview 2-1

A Brief History of BASIC 2-2

Visual Basic Statements and Expressions 2-3

Strict Type Checking 2-5

Visual Basic Arithmetic Operators 2-7

Comparison and Logical Operators 2-9

Concatenation Operators 2-11

Visual Basic Functions 2-12

String Functions 2-13

String Class Methods 2-17

Dates and Times 2-21

Random Number Object 2-24

Math Functions 2-25

Example 2-1: Savings Account 2-27

Tab Stops and Tab Order 2-32

Example 2-2: Savings Accounts – Setting Tabs 2-35

Improving a Visual Basic Application 2-36

Visual Basic Decisions - If Statements 2-37

Select Case - Another Way to Branch 2-40

Key Trapping 2-42

Control Focus 2-44

Example 2-3: Savings Account - Key Trapping 2-45

Visual Basic Looping 2-49

Visual Basic Counting 2-53

Example 2-4: Savings Account - Decisions 2-55

Class Review 2-62

Practice Problems 2 2-63

Problem 2-1. Random Number Problem

Problem 2-2. Price Problem

Problem 2-3. Odd Integers Problem

Problem 2-4. Pennies Problem

Problem 2-5. Code Problem

Exercise 2-1: Computing a Mean and Standard Deviation 2-64

Exercise 2-2: Flash Card Addition Problems 2-65

3. Object-Oriented Programming (OOP)

Review and Preview 3-1

Introduction to Object-Oriented Programming (OOP) 3-2

Objects in Visual Basic 3-4

Adding a Class to a Visual Basic Project 3-5

Declaring and Constructing an Object 3-7

Adding Properties to a Class 3-8

How Visual Basic Puts Controls on a Form 3-10

Another Way to Add Properties to a Class 3-12

Validating Class Properties 3-14

Adding Constructors to a Class 3-16

Adding Methods to a Class 3-18

Inheritance 3-23

Example 3-1. Savings Account 3-30

Inheriting from Visual Basic Controls 3-35

Building a Custom Control 3-36

Adding New Properties to a Control 3-40

Adding Control Event Procedures and Methods 3-43

Example 3-2. Savings Account (Revisited) 3-46

Class Review 3-48

Practice Problems 3 3-49

Problem 3-1. Mortgage Problem

Problem 3-2. Accelerated Mortgage Problem

Problem 3-3. Flashing Label Problem

Exercise 3: Mailing List 3-51

4. Exploring the Visual Basic Toolbox

Review and Preview 4-1

Function Overloading 4-2

MessageBox Dialog 4-3

Form Object 4-8

Button Control 4-11

Label Control 4-13

TextBox Control 4-15

Example 4-1: Password Validation 4-18

CheckBox Control 4-23

RadioButton Control 4-25

GroupBox Control 4-28

Panel Control 4-30

Handling Multiple Events in a Single Procedure 4-32

Control Arrays 4-35

Example 4-2: Pizza Order 4-37

ListBox Control 4-46

ComboBox Control 4-49

Example 4-3: Flight Planner 4-51

Class Review 4-56

Practice Problems 4 4-57

Problem 4-1. Message Box Problem

Problem 4-2. Tray Problem

Problem 4-3. List Box Problem

Problem 4-4. Combo Box Problem

Exercise 4: Customer Database Input Screen 4-58

5. More Exploration of the Visual Basic Toolbox

Review and Preview 5-1

Control Z Order 5-2

NumericUpDown Control 5-3

DomainUpDown Control 5-5

Example 5-1: Date Input Device 5-7

Horizontal and Vertical ScrollBar Controls 5-10

TrackBar Control 5-15

Example 5-2: Temperature Conversion 5-17

Picture Box Control 5-23

OpenFileDialog Control 5-29

Example 5-3: Picture Box Playground 5-32

Legacy Controls 5-38

DriveListBox Control 5-40

DirListBox Control 5-41

FileListBox Control 5-42

Synchronizing the Drive, Directory, and File List Box Controls 5-44

Example 5-4: Image Viewer 5-46

Class Review 5-53

Practice Problems 5 5-54

Problem 5-1. Tic-Tac-Toe Problem

Problem 5-2. Number Guess Problem

Problem 5-3. File Times Problem

Exercise 5: Student Database Input Screen 5-55

 

6. Windows Application Design and Distribution

Review and Preview 6-1

Application Design Considerations 6-2

Multiple Form Visual Basic Applications 6-3

Adding a Module 6-6

Visual Basic Multiple Document Interface (MDI) 6-7

Example 6-1: Shopping Cart 6-8

Using General Procedures in Applications 6-22

Example 6-2: Circle Geometry 6-27

Using General Functions in Applications 6-31

Example 6-3: Average Value 6-33

MenuStrip Control 6-39

ContextMenuStrip Control 6-45

Font Object 6-46

FontDialog Control 6-48

Example 6-4: Note Editor 6-50

Distribution of a Visual Basic Application 6-57

Application Icons 6-60

Visual Basic Setup Wizard 6-63

Debug Versus Release Configuration 6-75

Building the Setup Program 6-76

Installing/Removing a Visual Basic Application 6-77

ClickOnce Deployment 6-80

Class Review 6-81

Practice Problems 6 6-82

Problem 6-1. Note Editor About Box Problem

Problem 6-2. Normal Numbers Problem

Problem 6-3. Context Menu Problem

Exercise 6: US/World Capitals Quiz 6-83

7. Sequential Files, Error-Handling and Debugging

Review and Preview 7-1

Sequential Files 7-2

Sequential File Output (Variables) 7-5

Application Path 7-10

Example 7-1: Writing Variables to Sequential Files 7-11

Sequential File Input (Variables) 7-15

Example 7-2: Reading Variables from Sequential Files 7-18

Parsing Data Lines 7-27

Example 7-3. Parsing Data Lines 7-29

Building Data Lines 7-33

Example 7-4: Building Data Lines 7-35

Configuration Files 7-40

Example 7-5: Configuration Files 7-42

Writing and Reading Text Using Sequential Files 7-45

SaveFileDialog Control 7-48

Example 7-6: Note Editor - Reading and Saving Text Files 7-51

StreamWriter Object 7-54

StreamReader Object 7-58

Error Handling 7-61

Run-Time Error Trapping and Handling 7-63

Example 7-7: Note Editor - Error Trapping 7-66

Debugging Visual Basic Programs 7-69

Example 7-8: Debugging Example 7-71

Using the Debugging Tools 7-74

Debugging Strategies 7-88

Class Review 7-89

Practice Problems 7 7-90

Problem 7-1. Option Saving Problem

Problem 7-2. Text File Problem

Problem 7-3. Data File Problem

Problem 7-4. Debugging Problem

Exercise 7-1: Information Tracking 7-92

Exercise 7-2: ‘Recent Files’ Menu Option 7-93

 

8. Graphics Techniques with Visual Basic

Review and Preview 8-1

Simple Animation 8-2

Example 8-1: Simple Animation 8-4

Timer Control 8-7

Example 8-2: Timer Control 8-9

Basic Animation 8-11

Example 8-3: Basic Animation 8-13

Random Numbers (Revisited) and Games 8-18

Example 8-4: One-Buttoned Bandit 8-20

Randomly Sorting Integers 8-28

Example 8-5: Random Integers 8-29

Graphics Methods 8-33

Graphics Object 8-34

Colors 8-37

ColorDialog Control 8-39

Pen Object 8-42

DrawLine Method 8-44

Graphics Methods (Revisited) 8-45

Persistent Graphics 8-48

Example 8-6: Drawing Lines 8-51

Rectangle Structure 8-55

DrawRectangle Method 8-57

Brush Object 8-58

FillRectangle Method 8-59

DrawEllipse Method 8-60

FillEllipse Method 8-61

Example 8-7: Drawing Rectangles and Ellipses 8-62

DrawPie Method 8-70

FillPie Method 8-72

Example 8-8: Drawing Pie Segments 8-74

Pie Charts 8-80

Line Charts and Bar Charts 8-84

Coordinate Conversions 8-87

Example 8-9: Line, Bar and Pie Charts 8-96

8. Graphics Techniques with Visual Basic (cont.)

Class Review 8-105

Practice Problems 8 8-106

Problem 8-1. Bounce Problem

Problem 8-2. Dice Rolling Problem

Problem 8-3. Find the Burger Game

Problem 8-4. RGB Colors Problem

Problem 8-5. Plotting Problem

Problem 8-6. Pie Chart Problem

Exercise 8-1: Information Tracking Plotting 8-108

9. More Graphics Methods and Multimedia Effects

Review and Preview 9-1

Mouse Events 9-2

Example 9-1: Blackboard 9-5

Persistent Graphics, Revisited (Image and Bitmap Objects) 9-14

Example 9-2: Blackboard (Revisited) 9-17

More Graphics Methods 9-20

Point Structure 9-21

DrawLines Method 9-22

DrawPolygon Method 9-24

FillPolygon Method 9-25

DrawCurve Method 9-26

DrawClosedCurve Method 9-28

FillClosedCurve Method 9-29

Example 9-3: Drawing Lines, Polygons, Curves, Closed Curves 9-31

Example 9-4: Drawing Animated Lines and Curves 9-39

HatchBrush Object 9-42

Example 9-5: Hatch Brush 9-44

LinearGradientBrush Object 9-46

Example 9-6: Linear Gradient Brush 9-48

TextureBrush Object 9-50

Example 9-7: Texture Brush 9-51

DrawString Method 9-53

Multimedia Effects 9-59

Animation with DrawImage Method 9-60

Example 9-8: Bouncing Ball 9-62

Scrolling Backgrounds 9-68

Example 9-9: Horizontally Scrolling Background 9-71

Sprite Animation 9-75

Keyboard Events 9-78

Example 9-10. Sprite Animation 9-80

Collision Detection 9-85

Example 9-11: Collision Detection 9-86

Playing Sounds 9-91

Example 9-12: Bouncing Ball with Sound! 9-93

9. More Graphics Methods and Multimedia Effects (cont.)

Class Review 9-95

Practice Problems 9 9-96

Problem 9-1. Blackboard Problem

Problem 9-2. Rubber Band Problem

Problem 9-3. Shape Guessing Game

Problem 9-4. Plot Labels Problem

Problem 9-5. Bouncing Balls Problem

Problem 9-6. Moon Problem

Problem 9-7. Sound File Problem

Exercise 9: The Original Video Game - Pong! 9-97

10. Other Windows Application Topics

Review and Preview 10-1

Other Controls 10-2

LinkLabel Control 10-3

Example 10-1: Link Label Control 10-5

TabControl Control 10-7

Example 10-2: Tab Control 10-10

MonthCalendar Control 10-17

DateTimePicker Control 10-19

Example 10-3: Date Selections 10-20

RichTextbox Control 10-23

Example 10-4: Rich Text Box Example 10-26

ToolBar (Toolstrip) Control 10-29

Example 10-5: Note Editor Toolbar 10-33

ToolTip Control 10-38

Example 10-6: Tool Tip Control 10-39

Adding Controls at Run-Time 10-41

Example 10-7: Rolodex – Adding Controls at Run-Time 10-43

Printing with Visual Basic 10-46

Printing Pages of a Document 10-49

PageSetupDialog Control 10-56

PrintDialog Control 10-59

PrintPreviewDialog Control 10-61

Example 10-8: Printing 10-63

Using the Windows API 10-71

Timing with the Windows API 10-73

Example 10-9. Stopwatch Application (Revisited) 10-75

Adding a Help System to Your Application 10-77

Creating a Help File 10-79

Starting HTML Help Workshop 10-80

Creating Topic Files 10-82

Creating Table of Contents File 10-85

Compiling the Help File 10-90

HelpProvider Control 10-93

Example 10-10: Help System Display 10-95

10. Other Windows Application Topics (cont.)

Class Review 10-97

Practice Problems 10 10-98

Problem 10-2. Rich Textbox Note Editor Problem

Problem 10-3. Loan Printing Problem

Problem 10-4. Plot Printing Problem

Problem 10-5. Sound Timing Problem

Problem 10-6. Note Editor Help Problem

Exercise 10: Phone Directory 10-100

11. Visual Basic Database and Web Applications

Review and Preview 11-1

Database Applications 11-2

Database Structure and Terminology 11-3

DataSet Objects 11-7

Simple Data Binding 11-16

Database Navigation 11-19

Example 11-1: Accessing the Books Database 11-20

Creating a Virtual Table 11-26

Example 11-2: Creating a Virtual Table 11-27

DataView Objects 11-36

Example 11-3: ‘Rolodex’ Searching of the Books Database 11-39

Complex Data Binding 11-43

Web Applications 11-47

Starting a New Web Application 11-49

Web Form Controls 11-51

Building a Web Application 11-58

Example 11-4: Loan Payments 11-60

Example 11-5: Loan Repayment Schedule 11-65

Class Review 11-69

Course Summary 11-70

Practice Problems 11 11-71

Problem 11-1. New DataView Problem

Problem 11-2. Multiple Authors Problem

Problem 11-3. Stopwatch Problem

Exercise 11: The Ultimate Application 11-72

Practice Problems Solutions (Part 1: Classes 1 to 6) P1-1

Practice Problems Solutions (Part 2: Classes 7 to 11) P2-1

Exercise Solutions (Part 1: Classes 1 to 6) E1-1

Exercise Solutions (Part 2: Classes 7 to 11) E2-1