About the Book
This handy book is stuffed full of standalone,
working code samples that show Visual Basic programmers exactly how to
perform important tasks with Visual Basic .NET.
Getting up to speed with Visual Basic .NET
might seem challenging to programmers who already work in Visual Basic
6.0. This handy book is stuffed full of standalone, working code samples
that show these programmers exactly how to perform important tasks with
Visual Basic .NET. Each practical code sample covers a single essential
development concept—DataGrid sorting and filtering, for example—plus related
features to help programmers get up to speed quickly with Visual Basic
.NET. The samples are all written to exacting standards based on best coding
practices, and each is accompanied by helpful instructions, expert commentary,
and pointers to other books and resources. No other book offers so many
complete, standalone code samples and explanations—resulting in a useful
coding reference aimed at every level of expertise.
Related Books
Microsoft ® Visual Basic ® Professional
6.0 Step by Step
Programming Microsoft ® Visual Basic
® 6.0
Developing Microsoft ® .NET Controls
with Microsoft Visual Basic ® .NET
Table of Contents
Introduction
xxi
1 Working
with Microsoft Visual Studio .NET 2003 and Microsoft .NET Framework 1.1
1
Visual Studio .NET 2003 1
Changes to Add Web Reference 1
Coding Enhancements 3
Debugging Enhancements 5
Easy Access to the Object Browser 6
Changes to the Start Page 6
Code and Project Migration 7
Significant Framework Changes 8
Services Without Components 10
Application #101 New for 2003 12
Side-By-Side Execution 13
Windows Forms Applications 13
ASP.NET Applications 15
No-Touch Deployment 16
Components 17
Framework Configuration 17
Language Changes 18
Loop Variable Declaration 18
BitShift Operators 19
Additional Framework Changes 19
The ODBC Namespace 19
Enabling Windows XP Theme Support 20
Folder Browser 20
SpecialFolder Enumeration 21
System.IO 21
Conclusion 22
2 Working
with the Microsoft Visual Basic .NET Language 23
Application #1: Use Arrays 23
New Concepts 23
Code Walkthrough 25
Conclusion 29
Application #2: Use DateTimes 29
New Concepts 29
Code Walkthrough 30
Conclusion 35
Application #3: String Manipulation 35
New Concepts 35
Code Walkthrough 36
Conclusion 43
Application #4: Try...Catch...Finally 43
New Concepts 43
Structured Exception Handling Specifics 45
Code Walkthrough 46
Conclusion 50
Application #5: Custom Exceptions 50
New Concepts 50
Code Walkthrough 52
Conclusion 58
Application #6: Walking the Stack 58
New Concepts 59
Code Walkthrough 60
Conclusion 63
Application #7: Object-Oriented Features 64
New Concepts 64
Code Walkthrough 65
Conclusion 68
Application #8: Scoping, Overloading, Overriding 68
New Concepts 69
Code Walkthrough 71
Conclusion 78
Application #9: Use Callbacks 79
New Concepts 79
Code Walkthrough 80
Conclusion 83
Application #10: Use XML Comments 84
New Concepts 84
Code Walkthrough 84
Conclusion 88
Application #11: Key Visual Basic .NET Benefits 89
New Concepts 90
Code Walkthrough 91
Conclusion 94
3 Data
Access 95
Application #12: Use a DataSet and DataView 95
New Concepts 96
Code Walkthrough 97
Conclusion 100
Application #13: Use Stored Procedures 100
New Concepts 101
Code Walkthrough 102
Conclusion 105
Application #14: Use a SqlDataReader 105
New Concepts 106
Code Walkthrough 109
Conclusion 111
Application #15: Bind Data to a ComboBox 112
New Concepts 112
Code Walkthrough 113
Conclusion 116
Application #16: Data Binding with Navigation 116
New Concepts 117
Code Walkthrough 119
Conclusion 121
Application #17: Custom Data-Binding Format Handlers 121
New Concepts 122
Code Walkthrough 123
Conclusion 124
Application #18: Build a Master-Details Windows Form 124
New Concepts 125
Code Walkthrough 126
Conclusion 127
Application #19: Use a Typed DataSet 129
New Concepts 130
Code Walkthrough 133
Conclusion 135
Application #20: Build a Data-Entry Form 135
New Concepts 136
Code Walkthrough 136
Conclusion 140
Application #21: Build a Three-Tier Data Form 140
New Concepts 142
Code Walkthrough 143
Conclusion 146
Application #22: Build an Offline Application 147
New Concepts 148
Code Walkthrough 150
Conclusion 154
Application #23: Use T-SQL to Create Database Objects 154
New Concepts 155
Code Walkthrough 156
Conclusion 159
Application #24: Load Images from and Save Images to a Database 159
New Concepts 160
Code Walkthrough 161
Conclusion 164
Application #25: Use Legacy ADO 164
New Concepts 165
Code Walkthrough 166
Conclusion 168
Application #26: Use Crystal Reports 168
New Concepts 170
Code Walkthrough 172
Conclusion 174
Application #27: Compare Data Binding in Web and Windows Forms 174
New Concepts 175
Code Walkthrough 176
Conclusion 177
Application #28: Work with the XML DOM 178
New Concepts 179
Code Walkthrough 180
Conclusion 184
4 Building
Windows Forms User Interfaces 185
Application #29: Use the ListBox and ComboBox 186
New Concepts 187
Code Walkthrough 188
Conclusion 191
Application #30: Use Common Dialog Boxes 191
New Concepts 192
Code Walkthrough 194
Conclusion 199
Application #31: Validate Text Boxes 200
New Concepts 201
Code Walkthrough 202
Conclusion 205
Application #32: Use Format Codes to Format Data 205
New Concepts 206
Code Walkthrough 207
Conclusion 209
Application #33: Format a DataGrid 209
New Concepts 211
Code Walkthrough 212
Conclusion 214
Application #34: DataGrid Sorting and Filtering 215
New Concepts 216
Code Walkthrough 217
Conclusion 218
Application #35: Create an Explorer-Style Application 218
New Concepts 219
Code Walkthrough 220
Conclusion 223
Application #36: Create a System Tray Icon 223
New Concepts 224
Code Walkthrough 225
Conclusion 228
Application #37: Use Menus 228
New Concepts 229
Code Walkthrough 230
Conclusion 233
Application #38: Use Owner-Drawn Menus 233
New Concepts 234
Code Walkthrough 235
Conclusion 237
Application #39: Use the Clipboard 237
New Concepts 238
Code Walkthrough 239
Conclusion 241
Application #40: Use Drag-and-Drop 241
New Concepts 243
Code Walkthrough 244
Conclusion 246
Application #41: Simple Printing 246
New Concepts 247
Code Walkthrough 250
Conclusion 254
Application #42: Associate Help with an Application 254
New Concepts 255
Code Walkthrough 257
Conclusion 259
Application #43: XP Theme Support 259
New Concepts 260
Code Walkthrough 261
Conclusion 262
Application #44: Inherited Windows Forms 263
New Concepts 264
Code Walkthrough 265
Conclusion 267
Application #45: Create Top-Level Forms 267
New Concepts 268
Code Walkthrough 269
Conclusion 270
Application #46: Dynamic Control Creation 270
New Concepts 272
Code Walkthrough 272
Conclusion 274
5 Building
Web Applications 275
Application #47: Build Data-Entry Web Forms 275
New Concepts 276
Code Walkthrough 277
Conclusion 284
Application #48: Implement DataGrid Sorting 285
Code Walkthrough 286
Conclusion 289
Application #49: Implement DataGrid Paging 289
New Concepts 290
Code Walkthrough 291
Conclusion 293
Application #50: Expose a Simple Web Service 294
New Concepts 295
Code Walkthrough 295
Conclusion 297
Application #51: Consume a Web Service 298
New Concepts 299
Code Walkthrough 300
Conclusion 302
Application #52: Transfer Binary Data from a Web Service 302
New Concepts 303
Code Walkthrough 304
Conclusion 306
6 Working
with Console Applications 307
Application #53: Working with Console Applications 307
New Concepts 308
Code Walkthrough 309
Conclusion 312
7 Interacting
with the Operating System 313
Application #54: Work with Environment Settings 313
New Concepts 314
Code Walkthrough 314
Conclusion 315
Application #55: Use the File System 315
New Concepts 315
Code Walkthrough 316
Conclusion 318
Application #56: Receive File Notifications 318
New Concepts 319
Code Walkthrough 319
Conclusion 320
Application #57: Use the Event Log 320
New Concepts 320
Code Walkthrough 321
Conclusion 323
Application #58: Read and Write Performance Counters 323
New Concepts 323
Code Walkthrough 324
Conclusion 326
Application #59: Use the Process Class and Shell Functionality 326
New Concepts 326
Code Walkthrough 327
Conclusion 328
Application #60: View Process Information 328
New Concepts 328
Code Walkthrough 329
Conclusion 332
Application #61: Use WMI 332
New Concepts 333
Code Walkthrough 333
Conclusion 335
Application #62: Respond to System Events 335
New Concepts 335
Code Walkthrough 336
Conclusion 336
Application #63: Use the COM Port 336
New Concepts 337
Code Walkthrough 338
Conclusion 339
Application #64: Interact with Services 339
New Concepts 340
Code Walkthrough 340
Conclusion 341
Application #65: Interact with a Windows Service 342
New Concepts 342
Code Walkthrough 342
Conclusion 344
8 Working
with the .NET Framework 345
Application #66: Build a Custom Collection Class 345
New Concepts 346
Code Walkthrough 346
Conclusion 348
Application #67: Understand the Garbage Collector 349
New Concepts 349
Code Walkthrough 351
Conclusion 353
Application #68: Partition an Application 353
New Concepts 354
Code Walkthrough 355
Conclusion 359
Application #69: Send and Receive Data 359
New Concepts 359
Code Walkthrough 360
Conclusion 365
Application #70: Reflection 365
New Concepts 365
Examining Loaded Assemblies 366
Code Walkthrough 367
Conclusion 368
Application #71: Use MSMQ 369
New Concepts 369
Code Walkthrough 370
Conclusion 373
Application #72: Configuration Settings 373
New Concepts 373
Code Walkthrough 375
Conclusion 379
Application #73: Read From and Write To a Text File 380
New Concepts 380
Code Walkthrough 381
Conclusion 384
Application #74: Use Temporary Resources 384
New Concepts 384
Code Walkthrough 385
Conclusion 386
Application #75: Send Mail 386
New Concepts 386
Code Walkthrough 387
Conclusion 389
Application #76: Create and Use Trace Listeners 389
New Concepts 390
Code Walkthrough 390
Conclusion 394
Application #77: Use Regular Expressions 394
New Concepts 394
Code Walkthrough 394
Conclusion 396
9 Advanced
.NET Framework 397
Application #78: Create a Windows Service 397
New Concepts 398
Code Walkthrough 398
Conclusion 401
Application #79: Use Thread Pooling 401
New Concepts 403
Code Walkthrough 404
Conclusion 406
Application #80: Use Sockets 406
New Concepts 407
Code Walkthrough 408
Conclusion 410
Application #81: Work with Resource Files 411
New Concepts 412
Code Walkthrough 413
Conclusion 413
Application #82: Serialize Objects 413
New Concepts 414
Conclusion 417
Application #83: Use TCP Remoting 417
New Concepts 418
Code Walkthrough 419
Conclusion 420
Application #84: Asynchronous Calls 421
New Concepts 422
Code Walkthrough 422
Conclusion 424
10 GDI+
425
Application #85: Work with GDI+ Pens 425
New Concepts 426
Code Walkthrough 427
Conclusion 431
Application #86: Work with GDI+ Brushes 431
New Concepts 432
Code Walkthrough 433
Conclusion 436
Application #87: Work with GDI+ Text 436
New Concepts 437
Code Walkthrough 438
Conclusion 442
Application #88: Work with GDI+ to Manipulate Images 442
New Concepts 443
Code Walkthrough 444
Conclusion 448
Application #89: Create a Screen Saver with GDI+ 448
New Concepts 448
Code Walkthrough 449
Deploying the Screen Saver 454
Conclusion 454
Application #90: Animation 455
New Concepts 455
Code Walkthrough 456
Conclusion 460
11 Building
Enterprise Services Applications
461
Application #91: Create an Enterprise Services Component 461
New Concepts 462
Code Walkthrough 463
Conclusion 466
Application #92: Implement Role-Based Security 466
New Concepts 466
Code Walkthrough 467
Conclusion 472
12 COM
Interop/PInvoke 473
Application #93: Automate Office via COM Interop 473
New Concepts 474
Code Walkthrough 475
Conclusion 479
Application #94: Automate Internet Explorer via COM Interop 479
New Concepts 479
Code Walkthrough 480
Conclusion 484
Application #95: Make Win32 API Calls 484
New Concepts 484
Code Walkthrough 487
Conclusion 490
13 Visual
Studio .NET 491
Application #96: Create a Visual Studio .NET Add-In 491
New Concepts 491
Code Walkthrough 493
Conclusion 495
14 Securing
Applications 497
Application #97: Implement Windows Role-Based Security 497
New Concepts 498
Code Walkthrough 499
Conclusion 502
Application #98: Create a Login Dialog Box 502
New Concepts 503
Code Walkthrough 504
Conclusion 508
Application #99: Cryptographic Hash Algorithms 508
New Concepts 509
Code Walkthrough 510
Conclusion 512
Application #100: Encrypt and Decrypt Data 512
New Concepts 513
Code Walkthrough 515
Conclusion 518
15 Coding
Conventions 519
Why Are Coding Conventions Important? 519
How Much Is Too Much? 520
Coding Recommendations 521
Conclusion 528
16 Windows
Server 2003 for .NET Developers 529
Windows Server 2003 as an Application Server 529
.NET Framework 1.1 529
Internet Information Services (IIS) 6.0 530
IIS Architecture 530
IIS 6.0 Application Isolation 532
IIS 6.0 Application Pools 536
XML Metabase 538
Enterprise UDDI Services 540
What Is UDDI? 540
Active Directory 541
Active Directory Application Partitions 542
Active Directory Application Mode 542
COM+ 1.5 543
Microsoft Message Queue (MSMQ) 3.0 544
INDEX
545 |