Visual Basic 2005 for Programmers, 2/e Table of Contents
Preface xxiii
1 Introduction to .NET, Visual Basic and Object Technology 1
1.1 Introduction
1.2 Microsoft's Windows® Operating System
1.3 Visual Basic
1.4 The Internet and the World Wide Web
1.5 Extensible Markup Language (XML)
1.6 Microsoft's .NET
1.7 The .NET Framework and the Common Language Runtime
1.8 Test-Driving a Visual Basic Application
1.9 (Only Required Section of the Case Study) Software Engineering
Case Study: Introduction to Object Technology and the UML
1.10 Wrap-Up
1.11 Web Resources
2 Introduction to the Visual Basic Express 2005 IDE
2.1 Introduction
2.2 Overview of the Visual Studio 2005 IDE
2.3 Menu Bar and Toolbar
2.4 Navigating the Visual Studio IDE
2.4.1 Solution Explorer
2.4.2 Toolbox
2.4.3 Properties Window
2.5 Using Help
2.6 Using Visual Programming to Create a Simple Program
that Displays Text and an Image
2.7 Wrap-Up
2.8 Web Resources
3 Introduction to Visual Basic Programming
3.1 Introduction
3.2 Displaying a Line of Text
3.3 Creating A Console Application in Visual Basic Express
3.4 Displaying a Single Line of Text with Multiple Statements
3.5 Adding Integers
3.6 Arithmetic
3.7 Decision Making: Equality and Relational Operators
3.8 Using a Message Dialog to Display a Message
3.9 (Optional) Software Engineering Case Study: Examining the
ATM Requirements Document
3.10 Wrap-Up
3.11 Web Resources
4 Introduction to Classes and Objects
4.1 Introduction
4.2 Classes, Objects, Methods and Instance Variables
4.3 Declaring a Class with a Method and Instantiating an Object of a Class
4.4 Declaring a Method with a Parameter
4.5 Instance Variables and Properties
4.6 Value Types and Reference Types
4.7 Initializing Objects with Constructors
4.8 Validating Data with Set Accessors in Properties
4.9 (Optional) Software Engineering Case Study: Identifying the
Classes in the ATM Requirements Document
4.10 Wrap-Up
5 Control Statements: Part 1
5.1 Introduction
5.2 Control Structures
5.3 If Then Selection Statement
5.4 If Then Else Selection Statement
5.5 While Repetition Statement
5.6 Do While Loop Repetition Statement
5.7 Do Until Loop Repetition Statement
5.8 Compound Assignment Operators
5.9 Counter-Controlled Repetition
5.10 Sentinel-Controlled Repetition
5.11 Nested Control Statements
5.12 Nested Repetition Statements
5.13 Visual Basic Programming in a Windows Application
5.14 (Optional) Software Engineering Case Study: Identifying Class
Attributes in the ATM System
5.15 Wrap-Up
6 Control Statements: Part 2
6.1 Introduction
6.2 Essentials of Counter-Controlled Repetition
6.3 For Next Repetition Statement
6.4 Examples Using the For Next Statement
6.5 GradeBook Case Study: Select Case Multiple-Selection Statement
6.6 Do Loop While Repetition Statement
6.7 Do Loop Until Repetition Statement
6.8 Using the Exit Statement in Repetition Statements
6.9 Using the Continue Statement in Repetition Statements
6.10 Logical Operators
6.11 (Optional) Software Engineering Case Study: Identifying Objects'
States and Activities in the ATM System
6.12 Wrap-Up
7 Methods: A Deeper Look
7.1 Introduction
7.2 Modules, Classes and Methods
7.3 Subroutines: Methods That Do Not Return a Value
7.4 Functions: Methods That Return a Value
7.5 Shared Methods and Class Math 205
7.6 GradeBook Case Study: Declaring Methods with Multiple Parameters
7.7 Notes on Declaring and Using Methods
7.8 Method Call Stack and Activation Records
7.9 Implicit Argument Conversions
7.10 Option Strict and Data-Type Conversions
7.11 Value Types and Reference Types
7.12 Framework Class Library Namespaces
7.13 Passing Arguments: Pass-by-Value vs. Pass-by-Reference
7.14 Scope of Declarations
7.15 Case Study: Random Number Generation
7.16 Case Study: A Game of Chance
7.17 Method Overloading
7.18 Optional Parameters
7.19 Recursion
7.20 (Optional) Software Engineering Case Study: Identifying Class
Operations in the ATM System
7.21 Wrap-Up
8 Arrays
8.1 Introduction
8.2 Arrays
8.3 Declaring and Allocating Arrays
8.4 Examples Using Arrays
8.4.1 Allocating an Array
8.4.2 Initializing the Values in an Array
8.4.3 Summing the Elements of an Array
8.4.4 Using Arrays to Analyze Survey Results
8.4.5 Using Bar Charts to Display Array Data Graphically
8.4.6 Using the Elements of an Array as Counters
8.5 Case Study: Card Shuffling and Dealing Simulation
8.6 Passing an Array to a Method
8.7 For Each Next Repetition Statement
8.8 GradeBook Case Study: Using an Array to Store Grades
8.9 Rectangular Arrays
8.10 GradeBook Case Study: Using a Rectangular Array
8.11 Variable-Length Parameter Lists
8.12 Jagged Arrays
8.13 Changing the Size of an Array at Execution Time:
Using the ReDim Statement
8.14 Passing Arrays: ByVal vs. ByRef
8.15 (Optional) Software Engineering Case Study: Collaboration
Among Objects in the ATM System
8.16 Wrap-Up
9 Classes and Objects: A Deeper Look
9.1 Introduction
9.2 Time Class Case Study
9.3 Class Scope
9.4 Default and Parameterless Constructors
9.5 Time Class Case Study: Overloaded Constructors
9.6 Partial Classes
9.7 Composition
9.8 Using the Me Reference to Access the Current Object
9.9 Garbage Collection
9.10 Shared Class Members
9.11 Const and ReadOnly Members
9.12 Object Browser
9.13 Time Class Case Study: Creating Class Libraries
9.14 (Optional) Software Engineering Case Study: Starting to
Program the Classes of the ATM System
9.15 Wrap-Up
10 Object-Oriented Programming: Inheritance
10.1 Introduction
10.2 Base Classes and Derived Classes
10.3 Protected Members
10.4 Relationship between Base Classes and Derived Classes
10.4.1 Creating and Using a CommissionEmployee Class
10.4.2 Creating a BasePlusCommissionEmployee Class
without Using Inheritance
10.4.3 Creating a CommissionEmployeeBasePlusCommissionEmployee Inheritance Hierarchy
10.4.4 CommissionEmployeeBasePlusCommissionEmployee
Inheritance Hierarchy Using Protected Instance Variables
10.4.5 CommissionEmployeeBasePlusCommissionEmployee
Inheritance Hierarchy Using Private Instance Variables
10.5 Constructors in Derived Classes
10.6 Software Engineering with Inheritance
10.7 Class Object
10.8 Friend Members
10.9 Wrap-Up
11 Object-Oriented Programming: Polymorphism
11.1 Introduction
11.2 Polymorphic Video Game
11.3 Demonstrating Polymorphic Behavior
11.4 Abstract Classes and Methods
11.5 Case Study: Payroll System Class Hierarchy Using Polymorphism
11.5.1 Creating Abstract Base Class Employee
11.5.2 Creating Concrete Derived Class SalariedEmployee
11.5.3 Creating Concrete Derived Class HourlyEmployee
11.5.4 Creating Concrete Derived Class CommissionEmployee
11.5.5 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
11.5.6 Demonstrating Polymorphic Processing, Expression
TypeOf
Is, TryCast and Downcasting
11.5.7 Summary of the Allowed Assignments between Base
Class and Derived Class Variables
11.6 NotOverridable Methods and NotInheritable Classes
11.7 Case Study: Creating and Using Interfaces
11.7.1 Developing an IPayable Hierarchy
11.7.2 Declaring Interface IPayable
11.7.3 Creating Class Invoice
11.7.4 Modifying Class Employee to Implement Interface IPayable
11.7.5 Modifying Class SalariedEmployee for Use in the
IPayable Hierarchy
11.7.6 Using Interface IPayable to Process Invoices and Employees Polymorphically
11.7.7 Common Interfaces of the .NET Framework Class Library (FCL)
11.8 (Optional) Software Engineering Case Study: Incorporating
Inheritance and Polymorphism into the ATM System
11.9 Wrap-Up
12 Exception Handling
12.1 Introduction
12.2 Exception Handling Overview
12.3 Example: Divide by Zero Without Exception Handling
12.4 Example: Handling DivideByZeroExceptions and FormatExceptions
12.4.1 Enclosing Code in a Try Block
12.4.2 Catching Exceptions
12.4.3 Uncaught Exceptions
12.4.4 Termination Model of Exception Handling
12.4.5 Flow of Control When Exceptions Occur
12.5 .NET Exception Hierarchy
12.5.1 Classes ApplicationException and SystemException
12.5.2 Determining Which Exceptions a Method Throws
12.6 Finally Block
12.7 Exception Properties
12.8 User-Defined Exception Classes
12.9 Wrap-Up
13 Graphical User Interface Concepts: Part 1
13.1 Introduction
13.2 Windows Forms
13.3 Event Handling
13.3.1 A Simple Event-Driven GUI
13.3.2 Another Look at the Visual Studio Generated Code
13.3.3 Delegates and the Event-Handling Mechanism
13.3.4 Other Ways to Create Event Handlers
13.3.5 Locating Event Information
13.4 Control Properties and Layout
13.5 Labels, TextBoxes and Buttons
13.6 GroupBoxes and Panels
13.7 CheckBoxes and RadioButtons
13.8 PictureBoxes
13.9 ToolTips
13.10 NumericUpDown Control
13.11 Mouse-Event Handling
13.12 Keyboard-Event Handling
13.13 Wrap-Up
14 Graphical User Interface Concepts: Part 2
14.1 Introduction
14.2 Menus
14.3 MonthCalendar Control
14.4 DateTimePicker Control
14.5 LinkLabel Control
14.6 ListBox Control
14.7 CheckedListBox Control
14.8 ComboBox Control
14.9 TreeView Control
14.10 ListView Control
14.11 TabControl Control
14.12 Multiple Document Interface (MDI) Windows
14.13 Visual Inheritance
14.14 User-Defined Controls
14.15 Wrap-Up
15 Multithreading
15.1 Introduction
15.2 Thread States: Life Cycle of a Thread
15.3 Thread Priorities and Thread Scheduling
15.4 Creating and Executing Threads
15.5 Thread Synchronization and Class Monitor 570
15.6 Producer/Consumer Relationship without Thread Synchronization
15.7 Producer/Consumer Relationship with Thread Synchronization
15.8 Producer/Consumer Relationship: Circular Buffer
15.9 Multithreading with GUIs
15.10 Wrap-Up
16 Strings, Characters and Regular Expressions
16.1 Introduction
16.2 Fundamentals of Characters and Strings
16.3 String Constructors
16.4 String Indexer, Length Property and CopyTo Method
16.5 Comparing Strings
16.6 Locating Characters and Substrings in Strings
16.7 Extracting Substrings from Strings
16.8 Concatenating Strings
16.9 Miscellaneous String Methods
16.10 Class StringBuilder
16.11 Length and Capacity Properties, EnsureCapacity Method
and Indexer of Class StringBuilder
16.12 Append and AppendFormat Methods of Class StringBuilder
16.13 Insert, Remove and Replace Methods of Class StringBuilder
16.14 Char Methods
16.15 Card Shuffling and Dealing Simulation
16.16 Regular Expressions and Class RegEx
16.16.1 Regular Expression Example
16.16.2 Validating User Input with Regular Expressions
16.16.3 Regex methods Replace and Split
16.17 Wrap-Up
17 Graphics and Multimedia
17.1 Introduction
17.2 Drawing Classes and the Coordinate System
17.3 Graphics Contexts and Graphics Objects
17.4 Color Control
17.5 Font Control
17.6 Drawing Lines, Rectangles and Ovals
17.7 Drawing Arcs
17.8 Drawing Polygons and Polylines
17.9 Advanced Graphics Capabilities
17.10 Introduction to Multimedia
17.11 Loading, Displaying and Scaling Images
17.12 Animating a Series of Images
17.13 Windows Media Player
17.14 Microsoft Agent
17.15 Wrap-Up
18 Files and Streams
18.1 Introduction
18.2 Data Hierarchy
18.3 Files and Streams
18.4 Classes File and Directory
18.5 Creating a Sequential-Access Text File
18.6 Reading Data from a Sequential-Access Text File
18.7 Case Study: A Credit-Inquiry Program
18.8 Serialization
18.9 Creating a Sequential-Access File Using Object Serialization
18.10 Reading and Deserializing Data from a Sequential-Access Text File
18.11 Wrap-Up
19 Extensible Markup Language (XML)
19.1 Introduction
19.2 XML Basics
19.3 Structuring Data
19.4 XML Namespaces
19.5 Document Type Definitions (DTDs)
19.6 W3C XML Schema Documents
19.7 (Optional) Extensible Stylesheet Language and XSL Transformations
19.8 (Optional) Document Object Model (DOM)
19.9 (Optional) Schema Validation with Class XmlReader
19.10 (Optional) XSLT with Class XslCompiledTransform
19.11 Wrap-Up
19.12 Web Resources
20 Database, SQL and ADO.NET
20.1 Introduction
20.2 Relational Databases
20.3 Relational Database Overview: Books Database
20.4 SQL
20.4.1 Basic SELECT Query
20.4.2 WHERE Clause
20.4.3 ORDER BY Clause
20.4.4 Merging Data from Multiple Tables: INNER JOIN
20.4.5 INSERT Statement
20.4.6 UPDATE Statement
20.4.7 DELETE Statement
20.5 ADO.NET Object Model
20.6 Programming with ADO.NET: Extracting Information from a Database
20.6.1 Displaying a Database Table in a DataGridView
20.6.2 How Data Binding Works
20.7 Querying the Books Database
20.8 Programming with ADO.NET: Address Book Case Study
20.9 Using a DataSet to Read and Write XML
20.10 Wrap-Up
20.11 Web Resources
21 ASP.NET 2.0, Web Forms and Web Controls
21.1 Introduction
21.2 Simple HTTP Transactions
21.3 Multitier Application Architecture
21.4 Creating and Running a Simple Web-Form Example
21.4.1 Examining an ASPX File
21.4.2 Examining a Code-Behind File
21.4.3 Relationship Between an ASPX File and a Code-Behind File
21.4.4 How the Code in an ASP.NET Web Page Executes
21.4.5 Examining the XHTML Generated by an ASP.NET Application
21.4.6 Building an ASP.NET Web Application
21.5 Web Controls
21.5.1 Text and Graphics Controls
21.5.2 AdRotator Control
21.5.3 Validation Controls
21.6 Session Tracking
21.6.1 Cookies
21.6.2 Session Tracking with HttpSessionState
21.7 Case Study: Connecting to a Database in ASP.NET
21.7.1 Building a Web Form That Displays Data from a Database
21.7.2 Modifying the Code-Behind File for the Guestbook Application
21.8 Case Study: Secure Books Database Application
21.8.1 Examining the Completed Secure Books Database Application
21.8.2 Creating the Secure Books Database Application
21.9 Wrap-Up
21.10 Web Resources
22 Web Services
22.1 Introduction
22.2 .NET Web Services Basics
22.2.1 Creating a Web Service in Visual Web Developer
22.2.2 Determining a Web Service's Functionality
22.2.3 Testing a Web Service's Methods
22.2.4 Building a Client to Use a Web Service
22.3 Simple Object Access Protocol (SOAP)
22.4 Publishing and Consuming Web Services
22.4.1 Defining the HugeInteger Web Service
22.4.2 Building a Web Service in Visual Web Developer
22.4.3 Deploying the HugeInteger Web Service
22.4.4 Creating a Client to Consume the HugeInteger Web Service
22.4.5 Consuming the HugeInteger Web Service
22.5 Session Tracking in Web Services
22.5.1 Creating a Blackjack Web Service
22.5.2 Consuming the Blackjack Web Service
22.6 Using Web Forms and Web Services
22.6.1 Adding Data Components to a Web Service
22.6.2 Creating a Web Form to Interact with the Airline
Reservation Web Service
22.7 User-Defined Types in Web Services
22.8 Wrap-Up
22.9 Web Resources
23 Networking: Streams-Based Sockets and Datagrams
23.1 Introduction
23.2 Connection-Oriented vs. Connectionless Communication
23.3 Protocols for Transporting Data
23.4 Establishing a Simple TCP Server Using Stream Sockets
23.5 Establishing a Simple TCP Client Using Stream Sockets
23.6 Client/Server Interaction with Stream-Socket Connections
23.7 Connectionless Client/Server Interaction with Datagrams
23.8 Client/Server Tic-Tac-Toe Using a Multithreaded Server
23.9 WebBrowser Class
23.10 .NET Remoting
23.11 Wrap-Up
24 Data Structures
24.1 Introduction
24.2 Primitive-Type Structures; Boxing and Unboxing
24.3 Self-Referential Classes
24.4 Linked Lists
24.5 Stacks
24.6 Queues
24.7 Trees
24.7.1 Binary Search Tree of Integer Values
24.7.2 Binary Search Tree of IComparable Objects
24.8 Wrap-Up
25 Generics
25.1 Introduction
25.2 Motivation for Generic Methods
25.3 Generic Method Implementation
25.4 Type Constraints
25.5 Overloading Generic Methods
25.6 Generic Classes
25.7 Notes on Generics and Inheritance
25.8 Wrap-Up
26 Collections
26.1 Introduction
26.2 Collections Overview
26.3 Class Array and Enumerators
26.4 Non-Generic Collections
26.4.1 Class ArrayList
26.4.2 Class Stack
26.4.3 Class Hashtable
26.5 Generic Collections
26.5.1 Generic Class SortedDictionary
26.5.2 Generic Class LinkedList
26.6 Synchronized Collections
26.7 Wrap-Up
A Operator Precedence Chart
B Number Systems
B.1 Introduction
B.2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
B.3 Converting Octal and Hexadecimal Numbers to Binary Numbers
B.4 Converting from Binary, Octal or Hexadecimal to Decimal
B.5 Converting from Decimal to Binary, Octal or Hexadecimal
B.6 Negative Binary Numbers: Two's Complement Notation
C Using the Visual Studio 2005 Debugger
C.1 Introduction
C.2 Breakpoints and the Continue Command
C.3 The Locals and Watch Windows
C.4 Controlling Execution Using the Step Into, Step Over, Step Out
and Continue Commands
C.5 Other Features
C.5.1 Edit and Continue
C.5.2 Exception Assistant
C.5.3 Just My Code Debugging
C.5.4 Other New Debugger Features
C.6 Wrap-Up
D ASCII Character Set
E Unicode®
E.1 Introduction
E.2 Unicode Transformation Formats
E.3 Characters and Glyphs
E.4 Advantages/Disadvantages of Unicode
E.5 Unicode Consortium's Web Site
E.6 Using Unicode
E.7 Character Ranges
F Introduction to XHTML: Part 1
F.1 Introduction
F.2 Editing XHTML
F.3 First XHTML Example
F.4 W3C XHTML Validation Service
F.5 Headers
F.6 Linking
F.7 Images
F.8 Special Characters and More Line Breaks
F.9 Unordered Lists
F.10 Nested and Ordered Lists
F.11 Web Resources
G Introduction to XHTML: Part 2
G.1 Introduction
G.2 Basic XHTML Tables
G.3 Intermediate XHTML Tables and Formatting
G.4 Basic XHTML Forms
G.5 More Complex XHTML Forms
G.6 Internal Linking
G.7 Creating and Using Image Maps
G.8 meta Elements
G.9 frameset Element
G.10 Nested framesets
G.11 Web Resources
H XHTML Special Characters
I XHTML Colors
J ATM Case Study Code
J.1 ATM Case Study Implementation
J.2 Class ATM
J.3 Class Screen
J.4 Class Keypad
J.5 Class CashDispenser
J.6 Class DepositSlot
J.7 Class Account
J.8 Class BankDatabase
J.9 Class Transaction
J.10 Class BalanceInquiry
J.11 Class Withdrawal
J.12 Class Deposit
J.13 Module ATMCaseStudy
J.14 Wrap-Up
K UML 2: Additional Diagram Types
K.1 Introduction
K.2 Additional Diagram Types
L Primitive Types
Index
