Contents
Contents vii
Illustrations xxviii
Preface xxxvii
1 Introduction to Computers, Internet and
Visual Basic .NET 1
1.1 Introduction 2
1.2 What Is a Computer? 3
1.3 Computer Organization 4
1.4 Evolution of Operating Systems 5
1.5 Personal Computing, Distributed Computing and Client/Server Computing 5
1.6 Machine Languages, Assembly Languages and High-Level Languages 6
1.7 Visual Basic .NET 7
1.8 C, C++, Java™ and C# 9
1.9 Other High-Level Languages 10
1.10 Structured Programming 10
1.11 Key Software Trend: Object Technology 11
1.12 Hardware Trends 13
1.13 History of the Internet and World Wide Web 14
1.14 World Wide Web Consortium (W3C) 15
1.15 Extensible Markup Language (XML) 16
1.16 Introduction to Microsoft .NET 17
1.17 .NET Framework and the Common Language Runtime 18
1.18 Tour of the Book 20
1.19 Internet and World Wide Web Resources 29
VIII
2 Introduction to the Visual Studio .NET IDE 33
2.1 Introduction 34
2.2 Overview of the Visual Studio .NET IDE 34
2.3 Menu Bar and Toolbar 37
2.4 Visual Studio .NET IDE Windows 39
(Nested Control Structures) 119
4.14 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 4
(Nested Repetition Structures) 123
4.15 Introduction to Windows Application Programming 127
5 Control Structures: Part 2 144
5.1 Introduction 145
5.2 Essentials of Counter-Controlled Repetition 145
5.3 For/Next Repetition Structure 146
5.4 Examples Using the For/Next Structure 149
IX
5.5 Select Case Multiple-Selection Structure 155
5.6 Do/Loop While Repetition Structure 159
5.7 Do/Loop Until Repetition Structure 160
5.8 Using the Exit Keyword in a Repetition Structure 162
5.9 Logical Operators 164
5.10 Structured Programming Summary 170
6 Procedures 182
6.1 Introduction 183
6.2 Modules, Classes and Procedures 183
6.3 Sub Procedures 185
6.4 Function Procedures 188
6.5 Methods 190
6.6 Argument Promotion 195
6.7 Option Strict and Data-Type Conversions 196
6.8 Value Types and Reference Types 198
6.9 Passing Arguments: Pass-by-Value vs. Pass-by-Reference 200
6.10 Duration of Identifiers 202
6.11 Scope Rules 203
6.12 Random-Number Generation 206
6.13 Example: Game of Chance 213
8.3 Class Scope 306
8.4 Controlling Access to Members 306
8.5 Initializing Class Objects: Constructors 308
8.6 Using Overloaded Constructors 308
8.7 Properties 314
8.8 Composition: Objects as Instance Variables of Other Classes 321
8.9 Using the Me Reference 324
8.10 Garbage Collection 326
8.11 Shared Class Members 327
8.12 Const and ReadOnly Members 331
8.13 Data Abstraction and Information Hiding 334
8.14 Software Reusability 335
8.15 Namespaces and Assemblies 336
8.16 Class View and Object Browser 340
9 Object-Oriented Programming: Inheritance 349
9.1 Introduction 350
9.2 Base Classes and Derived Classes 351
9.3 Protected and Friend Members 354
9.4 Relationship between Base Classes and Derived Classes 354
9.5 Case Study: Three-Level Inheritance Hierarchy 372
9.6 Constructors and Finalizers in Derived Classes 376
9.7 Software Engineering with Inheritance 382
10 Object-Oriented Programming: Polymorphism 388
10.1 Introduction 389
10.2 Derived-Class-Object to Base-Class-Object Conversion 389
10.3 Type Fields and Select Case Statements 396
10.4 Polymorphism Examples 397
10.5 Abstract Classes and Methods 398
10.6 Case Study: Inheriting Interface and Implementation 400
10.7 NotInheritable Classes and NotOverridable Methods 408
13.4.2 CheckedListBoxes 542
13.5 ComboBoxes 545
13.6 TreeViews550
13.7 ListViews555
13.8 Tab Control 562
13.9 Multiple-Document-Interface (MDI) Windows 567
13.10 Visual Inheritance 576
13.11 User-Defined Controls 580
14 Multithreading 592
14.1 Introduction 593
14.2 Thread States: Life Cycle of a Thread 595
14.3 Thread Priorities and Thread Scheduling 596
14.4 Thread Synchronization and Class Monitor 601
14.5 Producer/Consumer Relationship without Thread Synchronization 603
14.6 Producer/Consumer Relationship with Thread Synchronization 609
14.7 Producer/Consumer Relationship: Circular Buffer 618
15 Strings, Characters and Regular Expressions 633
15.1 Introduction 634
15.2 Fundamentals of Characters and Strings 634
15.3 String Constructors 635
15.4 String Length and Chars Properties, and CopyTo Method 637
15.5 Comparing Strings639
XII
15.6 String Method GetHashCode 643
15.7 Locating Characters and Substrings in Strings644
15.8 Extracting Substrings from Strings647
15.9 Concatenating Strings648
15.10 Miscellaneous String Methods 649
15.11 Class StringBuilder 651
15.12 StringBuilder Indexer, Length and Capacity Properties,
17.10 Reading Data Sequentially from a Random-Access File 802
17.11 Case Study: A Transaction-Processing Program 807
18 Extensible Markup Language (XML) 833
18.1 Introduction 834
18.2 XML Documents 834
18.3 XML Namespaces 839
18.4 Document Object Model (DOM) 842
XIII
18.5 Document Type Definitions (DTDs), Schemas and Validation 860
18.5.1 Document Type Definitions 861
18.5.2 Microsoft XML Schemas 865
18.6 Extensible Stylesheet Language and XslTransform 870
18.7 Microsoft BizTalk™ 877
18.8 Internet and World Wide Web Resources 880
19 Database, SQL and ADO .NET 887
19.1 Introduction 888
19.2 Relational Database Model 889
19.3 Relational Database Overview: Books Database 890
19.4 Structured Query Language (SQL) 896
19.4.1 Basic SELECT Query 897
19.4.2 WHERE Clause 898
19.4.3 ORDER BY Clause 901
19.4.4 Merging Data from Multiple Tables: INNER JOIN 903
19.4.5 Joining Data from Tables Authors, AuthorISBN,
Titles and Publishers 906
19.4.6 INSERT Statement 909
19.4.7 UPDATE Statement 910
19.4.8 DELETE Statement 911
19.5 ADO .NET Object Model 912
19.6 Programming with ADO .NET: Extracting Information from a DBMS 913
21.9 Internet and World Wide Web Resources 1091
22 Networking: Streams-Based Sockets
and Datagrams 1096
22.1 Introduction 1097
22.2 Establishing a Simple Server (Using Stream Sockets) 1098
22.3 Establishing a Simple Client (Using Stream Sockets) 1100
22.4 Client/Server Interaction via Stream-Socket Connections 1101
22.5 Connectionless Client/Server Interaction via Datagrams 1110
22.6 Client/Server Tic-Tac-Toe Using a Multithreaded Server 1116
23 Data Structures and Collections 1136
23.1 Introduction 1137
23.2 Self-Referential Classes 1137
23.3 Linked Lists 1139
23.4 Stacks 1152
23.5 Queues 1156
23.6 Trees 1160
23.6.1 Binary Search Tree of Integer Values 1161
23.6.2 Binary Search Tree of IComparable Objects 1168
23.7 Collection Classes 1175
23.7.1 Class Array 1176
23.7.2 Class ArrayList 1179
23.7.3 Class Stack 1185
23.7.4 Class Hashtable 1189
24 Accessibility 1203
24.1 Introduction 1204
24.2 Regulations and Resources 1205
24.3 Web Accessibility Initiative 1207
24.4 Providing Alternatives for Images 1208
24.5 Maximizing Readability by Focusing on Structure 1209
24.6 Accessibility in Visual Studio .NET 1209
C Career Opportunities (on CD) 1280
C.1 Introduction 1281
C.2 Resources for the Job Seeker 1282
C.3 Online Opportunities for Employers 1283
C.3.1 Posting Jobs Online 1285
C.3.2 Problems with Recruiting on the Web 1287
C.3.3 Diversity in the Workplace 1287
C.4 Recruiting Services 1288
C.5 Career Sites 1289
C.5.1 Comprehensive Career Sites 1289
C.5.2 Technical Positions 1290
C.5.3 Wireless Positions 1290
C.5.4 Contracting Online 1291
C.5.5 Executive Positions 1292
C.5.6 Students and Young Professionals 1293
C.5.7 Other Online Career Services 1293
C.6 Internet and World Wide Web Resources 1294
D Visual Studio .NET Debugger 1302
D.1 Introduction 1303
D.2 Breakpoints 1304
D.3 Examining Data 1306
XVI
D.4 Program Control 1308
D.5 Additional Procedure Debugging Capabilities 1312
D.6 Additional Class Debugging Capabilities 1314
E ASCII Character Set 1319
F Unicode
®
(on CD) 1320
F.1 Introduction 1321
I.5 More Complex HTML Forms 1376
I.6 Internal Linking 1383
I.7 Creating and Using Image Maps 1386
I.8 <meta> Tags 1388
I.9 frameset Element 1390
XVII
I.10 Nested framesets 1392
I.11 Internet and World Wide Web Resources 1394
J Introduction to XHTML: Part 1 (on CD) 1400
J.1 Introduction 1401
J.2 Editing XHTML 1401
J.3 First XHTML Example 1402
J.4 W3C XHTML Validation Service 1405
J.5 Headers 1406
J.6 Linking 1408
J.7 Images 1411
J.8 Special Characters and More Line Breaks 1415
J.9 Unordered Lists 1417
J.10 Nested and Ordered Lists 1418
J.11 Internet and World Wide Web Resources 1421
K Introduction to XHTML: Part 2 (on CD) 1426
K.1 Introduction 1427
K.2 Basic XHTML Tables 1427
K.3 Intermediate XHTML Tables and Formatting 1430
K.4 Basic XHTML Forms 1432
K.5 More Complex XHTML Forms 1435
K.6 Internal Linking 1443
K.7 Creating and Using Image Maps 1446
K.8 meta Elements 1448
K.9 frameset Element 1449
2.15 Simple program executing. 45
2.16 Creating a new Windows Application.46
2.17 Setting the project location in the Project Location dialog. 47
2.18 Setting the form’s Text property. 47
2.19 Form with sizing handles.48
2.20 Changing the form’s BackColor property. 48
2.21 Adding a label to the form. 49
2.22 GUI after the form and label have been customized. 50
2.23 Properties window displaying the label’s properties. 50
2.24 Font dialog for selecting fonts, styles and sizes. 51
Illustrations XIX
2.25 Centering the label’s text. 51
2.26 Inserting and aligning the picture box. 52
2.27 Image property of the picture box. 52
2.28 Selecting an image for the picture box. 53
2.29 Picture box displaying an image. 53
2.30 IDE in run mode, with the running application in the foreground. 54
3 Introduction to Visual Basic Programming
3.1 Simple Visual Basic program. 63
3.2 Creating a Console Application with the New Project dialog. 65
3.3 IDE with an open console application. 66
3.4 Renaming the program file in the Properties window. 66
3.5 IntelliSense feature of the Visual Studio .NET IDE. 68
3.6 Parameter Info and Parameter List windows. 68
3.7 Executing the program shown in Fig. 3.1. 68
3.8 IDE indicating a syntax error. 69
3.9 Using multiple statements to print a line of text. 69
3.10 Addition program that adds two numbers entered by the user. 70
3.11 Dialog displaying a run-time error. 72
3.12 Memory location showing name and value of variable number1.74
solve the class-average problem. 112
4.14 Class-average program with counter-controlled repetition. 112
4.15 Pseudocode algorithm that uses sentinel-controlled repetition to
solve the class-average problem. 116
4.16 Class-average program with sentinel-controlled repetition. 117
4.17 Pseudocode for examination-results problem. 122
4.18 Nested control structures used to calculate examination results. 122
4.19 Second refinement of the pseudocode. 126
4.20 Nested repetition structures used to print a square of *s. 126
4.21 IDE showing program code for Fig. 2.15. 129
4.22 Windows Form Designer generated code when expanded. 130
4.23 Code generated by the IDE for lblWelcome.130
4.24 Properties window used to set a property value. 131
4.25 Windows Form Designer generated code reflecting new property values. 132
4.26 Changing a property in the code view editor. 132
4.27 New Text property value reflected in design mode. 132
4.28 Adding program code to FrmASimpleProgram_Load.133
4.29 Method FrmASimpleProgram_Load containing program code. 134
4.30 Changing a property value at runtime. 134
5 Control Structures: Part 2
5.1 Counter-controlled repetition with the While structure. 146
5.2 Counter-controlled repetition with the For/Next structure. 146
5.3 For/Next header components. 148
5.4 For/Next repetition structure flowchart. 149
5.5 For/Next structure used for summation. 150
5.6 Message dialog icon constants. 151
5.7 Message dialog button constants. 151
5.8 For/Next structure used to calculate compound interest. 152
5.9 Formatting codes for Strings. 154
5.10 Select Case structure used to count grades. 155
6.9 Property Pages dialog with Option Strict set to On.197
6.10 Visual Basic primitive data types. 198
6.11 Literals with type characters. 199
6.12 ByVal and ByRef used to pass value-type arguments. 201
6.13 Scoping rules in a class. 204
6.14 Random integers created by calling method Next of class Random.208
6.15 Demonstrates 4 die rolls. 209
6.16 Random class used to simulate rolling 12 six-sided dice. 211
6.17 Craps game using class Random.214
6.18 Recursive evaluation of 5!.219
6.19 Recursive factorial program. 220
6.20 Recursively generating Fibonacci numbers. 222
6.21 Recursive calls to method Fibonacci.224
6.22 Overloaded methods. 226
6.23 Syntax error generated from overloaded procedures with identical
parameter lists and different return types. 228
6.24 Optional argument demonstration with method Power.229
6.25 Module used to define a group of related procedures. 231
6.26 Testing the modDice procedures. 232
6.27 Printing the results of cubing 10 numbers. 238
6.28 Towers of Hanoi for the case with four disks. 244
7 Arrays
7.1 Array consisting of 12 elements. 247
7.2 Creating an array. 250
7.3 Initializing array elements two different ways. 251
7.4 Computing the sum of the elements in an array. 252
7.5 Simple student-poll analysis program. 254
XXII Illustrations
7.6 Program that prints histograms. 256
7.7 Using arrays to eliminate a Select Case structure. 257
8.18 Simple class library project. 338
8.19 Module modAssemblyTest references EmployeeLibrary.dll.339
8.20 Class View of Fig. 8.1 and Fig. 8.2. 341
8.21 Invoking the Object Browser from the development environment. 342
8.22 Object Browser when user selects Object from development
environment. 343
9 Object-Oriented Programming: Inheritance
9.1 Inheritance examples. 352
9.2 Inheritance hierarchy for university CCommunityMembers. 353
9.3 Portion of a CShape class hierarchy. 354
9.4 CPoint class represents an x-y coordinate pair. 355
9.5 modPointTest demonstrates class CPoint functionality. 357
Illustrations XXIII
9.6 CCircle class contains an x-y coordinate and a radius. 358
9.7 modCircleTest demonstrates class CCircle functionality. 360
9.8 CCircle2 class that inherits from class CPoint.362
9.9 CPoint2 class represents an x-y coordinate pair as Protected data. 364
9.10 CCircle3 class that inherits from class CPoint2. 365
9.11 modCircleTest3 demonstrates class CCircle3 functionality. 367
9.12 CCircle4 class that inherits from class CPoint, which does not
provide Protected data. 369
9.13 modCircleTest4 demonstrates class CCircle4 functionality. 371
9.14 CCylinder class inherits from class CCircle4 and Overrides
method Area. 373
9.15 Testing class CCylinder. 375
9.16 CPoint3 base class contains constructors and finalizer. 378
9.17 CCircle5 class inherits from class CPoint3 and overrides a
finalizer method. 379
9.18 Demonstrating order in which constructors and finalizers are called. 381
10 Object-Oriented Programming: Polymorphism
DivideByZeroException.447
11.2 Finally statements always execute, regardless of whether an
exception occurs. 454
11.3 Exception properties and stack unwinding. 462
11.4 ApplicationException derived class thrown when a program
performs an illegal operation on a negative number. 465
11.5 FrmSquareRoot class throws an exception if an error occurs
when calculating the square root. 466
11.6 OverflowException cannot occur if user disables
integer-overflow checking. 468
12 Graphical User Interface Concepts: Part 1
12.1 GUI components in a sample Internet Explorer window. 477
12.2 Some basic GUI components. 477
12.3 Components and controls for Windows Forms. 478
12.4 Common Form properties, methods and events. 479
12.5 Event-handling model using delegates. 480
12.6 Events section in the Method Name drop-down menu. 482
12.7 Simple event-handling example using visual programming. 482
12.8 List of Form events. 486
12.9 Click event details. 486
12.10 Class Control properties and methods. 487
12.11 Anchoring demonstration. 489
12.12 Manipulating the Anchor property of a control. 489
12.13 Docking demonstration. 490
12.14 Control layout properties. 490
12.15 Common Label properties. 491
12.16 TextBox properties and events. 492
12.17 Button properties and events. 493
12.18 Program to display hidden text in a password box. 493
12.19 GroupBox properties. 495
user selection. 544
13.15 ComboBox demonstration. 546
13.16 ComboBox properties and events. 546
13.17 ComboBox used to draw a selected shape. 547
13.18 TreeView displaying a sample tree. 550
13.19 TreeView properties and events. 550
13.20 TreeNode properties and methods. 551
13.21 TreeNode Editor.552
13.22 TreeView used to display directories. 553
13.23 ListView properties and events. 556
13.24 Image Collection Editor window for an ImageList component. 556
13.25 ListView displaying files and folders. 557
13.26 Tabbed windows in Visual Studio .NET. 562
13.27 TabControl with TabPages example. 563
13.28 TabPages added to a TabControl.563
13.29 TabControl properties and events. 564
13.30 TabControl used to display various font settings. 564
13.31 MDI parent window and MDI child windows. 568
13.32 SDI and MDI forms. 568
13.33 MDI parent and MDI child events and properties. 569
13.34 Minimized and maximized child windows. 570
13.35 MenuItem property MdiList example. 571
13.36 LayoutMdi enumeration values. 572
13.37 MDI parent-window class. 572
13.38 MDI child FrmChild. 575
13.39 Class FrmInheritance, which inherits from class Form, contains
a button (Learn More). 577
13.40 Visual Inheritance through the Form Designer. 578
XXVI Illustrations
13.41 Class FrmVisualTest, which inherits from class
15.2 String Length and Chars properties, and CopyTo method. 637
15.3 String test to determine equality. 639
15.4 StartsWith and EndsWith methods. 642
15.5 GetHashCode method demonstration. 643
15.6 Searching for characters and substrings in Strings. 644
15.7 Substrings generated from Strings. 647
15.8 Concat Shared method. 648
15.9 String methods Replace, ToLower, ToUpper,
Trim and ToString.649
15.10 StringBuilder class constructors . 651
15.11 StringBuilder size manipulation. 653
15.12 Append methods of StringBuilder.655
15.13 StringBuilder’s AppendFormat method. 656
15.14 StringBuilder text insertion and removal. 658
Illustrations XXVII
15.15 StringBuilder text replacement. 659
15.16 Char’s Shared character-testing methods and case-conversion methods. 661
15.17 CCard class. 663
15.18 Card dealing and shuffling simulation. 664
15.19 Character classes. 668
15.20 Regular expressions checking birthdays. 668
15.21 Quantifiers used regular expressions. 670
15.22 Validating user information using regular expressions. 670
15.23 Regex methods Replace and Split.675
16 Graphics and Multimedia
16.1 System.Drawing namespace’s Classes and Structures. 685
16.2 GDI+ coordinate system. Units are measured in pixels. 686
16.3 Color structure Shared constants and their RGB values. 688
16.4 Color structure members. 688
16.5 Classes that derive from class Brush.689
XXVIII Illustrations
16.36 Peedy calculating the total. 737
16.37 Microsoft Agent demonstration. 738
16.38 GUI for eight queens exercise. 751
17 Files and Streams
17.1 Data hierarchy. 755
17.2 Visual Basic’s view of an n-byte file. 756
17.3 File class methods (partial list). 757
17.4 Directory class methods (partial list). 758
17.5 FrmFileTest class tests classes File and Directory. 759
17.6 FrmFileSearch class uses regular expressions to determine file types. 762
17.7 FrmBankUI class is the base class for GUIs in our
file-processing applications. 767
17.8 CRecord class represents a record for sequential-access file-processing
applications. 770
17.9 FrmCreateSequentialAccessFile class creates and writes
to sequential-access files. 772
17.10 Sample data for the program of Fig. 17.9. 779
17.11 FrmReadSequentialAccessFile class reads sequential-access files. 779
17.12 FrmCreditInquiry class is a program that displays credit inquiries. 783
17.13 Random-access file with fixed-length records. 790
17.14 CRandomAccessRecord class represents a record for
random-access file-processing applications. 791
17.15 FrmCreateRandomAccessFile class create files for
random-access file-processing applications. 794
17.16 FrmWriteRandomAccessFile class writes records to r
andom-access files. 798
17.17 FrmReadRandomAccessFile class reads records from
random-access files sequentially. 802
17.18 CTransaction class handles record transactions for the
18.17 Schema file that contains structure to which book.xml conforms. 866
18.18 Schema-validation example. 867
18.19 XML file that does not conform to the Schema in Fig. 18.17. 869
18.20 XML document containing book information. 871
18.21 XSL document that transforms sorting.xml into XHTML. 872
18.22 XSL style sheet applied to an XML document. 875
18.23 BizTalk terminology. 877
18.24 BizTalk markup using an offer Schema. 878
19 Database, SQL and ADO .NET
19.1 Relational-database structure of an Employee table. 889
19.2 Result set formed by selecting Department and Location data
from the Employee table. 890
19.3 Authors table from Books.890
19.4 Data from the Authors table of Books.890
19.5 Publishers table from Books.891
19.6 Data from the Publishers table of Books.891
19.7 AuthorISBN table from Books.892
19.8 Data from AuthorISBN table in Books.892
19.9 Titles table from Books.893
19.10 Data from the Titles table of Books. 893
19.11 Table relationships in Books.896
19.12 SQL query keywords. 897
19.13 authorID and lastName from the Authors table. 898
19.14 Titles with copyrights after 1999 from table Titles.899
19.15 Authors from the Authors table whose last names start with D.900
19.16 Authors from table Authors whose last names contain i as their
second letter. 901
19.17 Authors from table Authors in ascending order by lastName.901
19.18 Authors from table Authors in descending order by lastName.902
19.19 Authors from table Authors in ascending order by lastName
20.10 Web Forms menu in the Toolbox.954
20.11 Design mode of Web Form designer. 954
20.12 HTML mode of Web-Form designer. 955
20.13 Code-behind file for WebForm1.aspx generated by Visual Studio .NET. 956
20.14 FlowLayout and GridLayout illustration. 956
20.15 WebForm.aspx after adding two Labels and setting their properties. 957
20.16 Commonly used Web controls. 958
20.17 Web-controls demonstration. 959
20.18 AdRotator class demonstrated on a Web form. 964
20.19 Code-behind file for page demonstrating the AdRotator class. 965
20.20 AdvertisementFile used in AdRotator example. 967
20.21 Validators used in a Web Form that generates possible letter
combinations from a phone number. 970
20.22 Code-behind file for the word-generator page. 972
20.23 HTML and JavaScript sent to the client browser. 976
20.24 ASPX file that presents a list of programming languages x. 981
20.25 Code-behind file that writes cookies to the client. 983
20.26 ASPX page that displays book information. 986
20.27 Cookies being read from a client in an ASP .NET application. 987
Illustrations XXXI
20.28 HttpCookie properties. 989
20.29 Options supplied on an ASPX page. 989
20.30 Sessions are created for each user in an ASP .NET Web application. 991
20.31 HttpSessionState properties. 995
20.32 Session information displayed in a ListBox.995
20.33 Session data read by an ASP .NET Web application to provide
recommendations for the user. 996
20.34 Guest-book application GUI. 998
20.35 ASPX file for the guest-book application. 999
20.36 Code-behind file for the guest-book application. 1001
21.22 Receiving temperature and weather data from a Web service. 1077
21.23 Class that stores equation information. 1082
21.24 Web service that generates random equations. 1085
21.25 Returning an object from a Web-service method. 1086
21.26 Math-tutor application. 1087