Tải bản đầy đủ (.pdf) (2,182 trang)

Visual basic2005 in AN

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (0 B, 2,182 trang )

This document is created with a trial version of CHM2PDF Pilot


Visual Basic 2005: In a Nutshell, 3rd Edition
By Paul Lomax, Tim Patrick, Ron Petrusha, Steven Roman, Ph.D.
...............................................
Publisher: O'Reilly
Pub Date: January 2006
Print ISBN-10: 0-596-10152-X
Print ISBN-13: 978-0-59-610152-7
Pages: 766

Table of Contents | Index

When Microsoft made Visual Basic into an object-oriented programming language, millions of VB developers resisted
the change to the .NET platform. Now, after integrating feedback from their customers and creating Visual Basic
2005, Microsoft finally has the right carrot. Visual Basic 2005 offers the power of the .NET platform, yet restores the
speed and convenience of Visual Basic. Accordingly, we've revised the classic in a Nutshell guide to the Visual Basic
language to cover the Visual Basic 2005 version and all of its new features.

Unlike other books on the subject, Visual Basic 2005 in a Nutshell, 3rd Edition doesn't assume you're a novice. It's a
detailed, professional reference to the Visual Basic language-a reference that you can use to jog your memory about
a particular language element or parameter. It'll also come in handy when you want to make sure that there isn't
some "gotcha" you've overlooked with a particular language feature.

The book is divided into three major parts: Part I introduces the main features and concepts behind Visual Basic
programming; Part II thoroughly details all the functions, statements, directives, objects, and object members that
make up the Visual Basic language; and Part III contains a series of helpful appendices. Some of the new features
covered include Generics, a convenient new library called My Namespace, and the operators used to manipulate data
in Visual Basic.


No matter how much experience you have programming with Visual Basic, you want Visual Basic 2005 in a Nutshell,
3rd Edition close by, both as a standard reference guide and as a tool for troubleshooting and identifying
programming problems.


This document is created with a trial version of CHM2PDF Pilot


Visual Basic 2005: In a Nutshell, 3rd Edition
By Paul Lomax, Tim Patrick, Ron Petrusha, Steven Roman, Ph.D.
...............................................
Publisher: O'Reilly
Pub Date: January 2006
Print ISBN-10: 0-596-10152-X
Print ISBN-13: 978-0-59-610152-7
Pages: 766

Table of Contents | Index

Copyright
Preface
Why Another Visual Basic Book?
Who This Book Is For
How This Book Is Structured
About the Third Edition
Using Code Examples
Conventions Used in This Book
Safari® Enabled
How to Contact Us
Acknowledgments

Part I: The Basics
Chapter 1. Introduction
Section 1.1. Why Visual Basic .NET?
Section 1.2. What Is Visual Basic .NET?
Section 1.3. What Can You Do with Visual Basic .NET?
Section 1.4. Versions of Visual Basic for .NET
Chapter 2. The .NET Framework: General Concepts
Section 2.1. Common Language Runtime
Section 2.2. Managed Code
Section 2.3. Namespaces
Section 2.4. Types and Objects
Section 2.5. Assemblies
Section 2.6. The Framework Class Library
Section 2.7. Application Deployment
Section 2.8. The .NET Framework and Visual Basic
Chapter 3. Introduction to Object-Oriented Programming
Section 3.1. Principles of Object-Oriented Programming
Section 3.2. OOP Development in Visual Basic
Chapter 4. Variables and Data Types
Section 4.1. Data Types
Section 4.2. Variables
Section 4.3. Constants
Section 4.4. Enumerations
Section 4.5. Arrays
Section 4.6. Collections
Section 4.7. Parameters and Arguments
Chapter 5. Operators
Section 5.1. Arithmetic Operators
Section 5.2. Concatenation Operators



This document is created with a trial version of CHM2PDF Pilot

Section 5.3. Logical and Bitwise Operators
Section 5.4. Assignment Operators
Section 5.5. Comparison Operators
Section 5.6. Object Operators
Section 5.7. Operator Overloading
Section 5.8. Operator Precedence
Chapter 6. Program Structure
Section 6.1. Visual Studio Application Types
Section 6.2. Referencing Components and Classes
Section 6.3. Application Entry Points
Section 6.4. Code File Contents
Section 6.5. The Structure of a Visual Basic Program
Chapter 7. The .NET Framework Class Library
Section 7.1. The System Namespace
Section 7.2. The System.Collections Namespace
Section 7.3. The System.Data Namespace
Section 7.4. The System.IO Namespace
Section 7.5. The System.Text.RegularExpressions Namespace
Section 7.6. The System.Windows.Forms Namespace
Section 7.7. Other Namespaces
Chapter 8. Delegates and Events
Section 8.1. Delegates
Section 8.2. Events and Event Binding
Chapter 9. Attributes
Section 9.1. Syntax and Use
Section 9.2. Defining a Custom Attribute
Section 9.3. Using a Custom Attribute

Chapter 10. Generics
Section 10.1. What Are Generics?
Section 10.2. Type Parameters
Section 10.3. Multiple Type Parameters
Section 10.4. Constraints
Section 10.5. Multiple Constraints
Section 10.6. Accessing Type Parameter Members
Section 10.7. Generic Methods
Section 10.8. Nested Generic Types
Section 10.9. Overloaded Types and Members
Chapter 11. Error Handling in Visual Basic
Section 11.1. Error Detection and Error Handling
Section 11.2. Runtime Error Handling
Section 11.3. Dealing with Logic Errors
Section 11.4. Error Constants
Part II: Reference
Chapter 12. The Language Reference
#Const Directive
#If...Then...#Else Directive
#Region...#End Region Directive
Abs Function
Acos Function
AddHandler Statement
AddressOf Operator
AppActivate Procedure
Application Class


This document is created with a trial version of CHM2PDF Pilot


Application Class
Application.CompanyName Property
Application.DoEvents Method
Application.ExecutablePath Property
Application.ProductName Property
Application.ProductVersion Property
Application.Run Method
Array Class
Array.BinarySearch Method
Array.Copy Method
Array.IndexOf Method
Array.LastIndexOf Method
Array.Reverse Method
Array.Sort Method
Asc, AscW Functions
AssemblyVersion Attribute
Asin Function
Atan Function
Atan2 Function
AttributeUsage Attribute
Beep Procedure
Call Statement
CallByName Function
CBool Function
CByte Function
CChar Function
CDate Function
CDbl Function
CDec Function
Ceiling Function

ChDir Procedure
ChDrive Procedure
Choose Function
Chr, ChrW Functions
CInt Function
Class...End Class Statement
Clipboard Class
CLng Function
CLSCompliant Attribute
CObj Function
Collection Class
Collection.Add Method
Collection.Count Property
Collection.Item Property
Collection.Remove Method
ColorDialog Class
COMClass Attribute
Command Function
Const Statement
Continue Statement
Cos Function
Cosh Function
CreateObject Function


This document is created with a trial version of CHM2PDF Pilot

CSByte Function
CShort Function
CSng Function

CStr Function
CType Function
CUInt Function
CULng Function
CUShort Function
CurDir Function
Custom Event Statement
DateAdd Function
DateDiff Function
DatePart Function
DateSerial Function
DateString Property
DateValue Function
Day Function
DDB Function
Debug Class
Debug.Assert Method
Debug.Listeners Property
Debug.Write Method
Debug.WriteIf Method
Debug.WriteLine Method
Debug.WriteLineIf Method
Declare Statement
DefaultMember Attribute
Delegate Statement
DeleteSetting Procedure
Dim Statement
Dir Function
DirectCast Function
Directory Class

Directory.CreateDirectory Method
Directory.Delete Method
Directory.Exists Method
Directory.GetCreationTime Method
Directory.GetDirectories Method
Directory.GetDirectoryRoot Method
Directory.GetFiles Method
Directory.GetFileSystemEntries Method
Directory.GetLogicalDrives Method
Directory.GetParent Method
Directory.Move Method
Do...Loop Statement
E Field
End Statement
Enum Statement
Environ Function
EOF Function
Erase Statement
Erl Property
Err Object


This document is created with a trial version of CHM2PDF Pilot

Err Object
Err.Clear Method
Err.Description Property
Err.GetException Method
Err.HelpContext Property
Err.HelpFile Property

Err.LastDLLError Property
Err.Number Property
Err.Raise Method
Err.Source Property
Error Statement
ErrorToString Function
Event Statement
Exception Class
Exit Statement
Exp Function
File Class
File.Exists Method
FileAttr Function
FileClose Procedure
FileCopy Procedure
FileDateTime Function
FileGet, FileGetObject Procedures
FileLen Function
FileOpen Procedure
FilePut, FilePutObject Procedures
FileWidth Procedure
Filter Function
Fix Function
Flags Attribute
Floor Function
FontDialog Class
For...Next Statement
For Each...Next Statement
Format Function
FormatCurrency, FormatNumber, FormatPercent Functions

FormatDateTime Function
FreeFile Function
Friend Keyword
Function Statement
FV Function
GetAllSettings Function
GetAttr Function
GetChar Function
GetObject Function
GetSetting Function
GetType Operator
Global Keyword
GoTo Statement
Guid Attribute
Handles Keyword
Hashtable Class
Hashtable.Add Method


This document is created with a trial version of CHM2PDF Pilot

Hashtable.ContainsKey Method
Hashtable.ContainsValue Method
Hashtable.CopyTo Method
Hashtable.Item Property
Hashtable.Keys Property
Hashtable.Remove Method
Hashtable.Values Property
Hex Function
Hour Function

IEEERemainder Function
If...Then...Else Statement
IIf Function
Implements Keyword
Implements Statement
Imports Statement
Inherits Statement
Input Procedure
InputBox Function
InputString Function
InStr Function
InStrRev Function
Int Function
Interface...End Interface Statement
IPmt Function
IRR Function
Is Operator
IsArray Function
IsDate Function
IsDBNull Function
IsError Function
IsNot Operator
IsNothing Function
IsNumeric Function
IsReference Function
Join Function
Kill Procedure
LBound Function
LCase Function
Left Function

Len Function
Like Operator
LineInput Function
Loc Function
Lock Procedure
LOF Function
Log Function
Log10 Function
LSet Function
LTrim Function
MarshalAs Attribute
Max Function
Me Keyword
Mid Function


This document is created with a trial version of CHM2PDF Pilot

Mid Function
Mid Statement
Min Function
Minute Function
MIRR Function
MkDir Procedure
Mod Operator
Module...End Module Statement
Month Function
MonthName Function
MsgBox Function
MTAThread Attribute

MyBase Keyword
MyClass Keyword
Namespace Statement
New Keyword
Nothing Keyword
Now Property
NPer Function
NPV Function
Obsolete Attribute
Oct Function
Of Keyword
On Error Statement
OpenFileDialog Class
Operator Statement
Option Compare Statement
Option Explicit Statement
Option Strict Statement
Out Attribute
ParamArray Attribute
Partial Keyword
Partition Function
PI Field
Pmt Function
Pow Function
PPmt Function
Print, PrintLine Procedures
Private Keyword
Property Statement
Protected Keyword
Public Keyword

PV Function
QBColor Function
Queue Class
Queue.Contains Method
Queue.CopyTo Method
Queue.Dequeue Method
Queue.Enqueue Method
Queue.Peek Method
Queue.ToArray Method
RaiseEvent Statement
Randomize Procedure


This document is created with a trial version of CHM2PDF Pilot

Rate Function
ReDim Statement
Rem Statement
RemoveHandler Statement
Rename Procedure
Replace Function
Reset Procedure
Resume Statement
Return Statement
RGB Function
Right Function
RmDir Procedure
Rnd Function
Round Function
RSet Function

RTrim Function
SaveFileDialog Class
SaveSetting Procedure
ScriptEngine Property
ScriptEngineBuildVersion Property
ScriptEngineMajorVersion Property
ScriptEngineMinorVersion Property
Second Function
Seek Function
Seek Procedure
Select Case Statement
Send, SendWait Methods
SetAttr Procedure
Shadows Keyword
Shared Keyword
Shell Function
Sign Function
Sin Function
Sinh Function
SLN Function
Space Function
SPC Function
Split Function
Sqrt Function
Stack Class
Stack.Contains Method
Stack.CopyTo Method
Stack.Peek Method
Stack.Pop Method
Stack.Push Method

Stack.ToArray Method
STAThread Attribute
Static Statement
Stop Statement
Str Function
StrComp Function
StrConv Function
StrDup Function


This document is created with a trial version of CHM2PDF Pilot

StrDup Function
StrReverse Function
Structure...End Structure Statement
Sub Statement
Switch Function
SYD Function
SyncLock Statement
SystemTypeName Function
TAB Function
Tan Function
Tanh Function
ThreadStatic Attribute
Throw Statement
TimeOfDay Property
Timer Property
TimeSerial Function
TimeString Property
TimeValue Function

Today Property
Trim Function
Try...Catch...Finally Statement
TryCast Function
TypeName Function
TypeOf Operator
UBound Function
UCase Function
Unlock Procedure
Using...End Using Statement
Val Function
VarType Function
VBFixedArray Attribute
VBFixedString Attribute
VbTypeName Function
WebMethod Attribute
WebService Attribute
Weekday Function
WeekdayName Function
While...End While Statement
With...End With Statement
WithEvents Keyword
Write, WriteLine Procedures
Year Function
Chapter 13. The 'My' Reference
AllUsersApplicationData Property
AltKeyDown Property
Application Object
ApplicationContext Property
AssemblyName Property

Audio Object
AvailablePhysicalMemory Property
AvailableVirtualMemory Property
ButtonsSwapped Property
CapsLock Property


This document is created with a trial version of CHM2PDF Pilot

ChangeCulture Method
ChangeUICulture Method
ClassesRoot Property
Clear Method
Clipboard Object
Clock Object
Close Method
CombinePath Method
CommandLineArgs Property
CommentTokens Property
CompanyName Property
Computer Object
ContainsAudio Method
ContainsData Method
ContainsFileDropList Method
ContainsImage Method
ContainsText Method
CopyDirectory Method
CopyFile Method
Copyright Property
CreateDirectory Method

CtrlKeyDown Property
Culture Property
CurrentConfig Property
CurrentDirectory Property
CurrentPrincipal Property
CurrentUser Property
CurrentUserApplicationData Property
DefaultFileLogWriter Property
DeleteDirectory Method
DeleteFile Method
Delimiters Property
Deployment Property
Description Property
Desktop Property
DirectoryExists Method
DirectoryPath Property
DoEvents Method
DownloadFile Method
Drives Property
DynData Property
EndOfData Property
ErrorLine Property
ErrorLineNumber Property
FieldWidths Property
FileExists Method
FileSystem Object
FindInFiles Method
Forms Object
GetAudioStream Method
GetData Method

GetDataObject Method
GetDirectories Method


This document is created with a trial version of CHM2PDF Pilot

GetDirectories Method
GetDirectoryInfo Method
GetDriveInfo Method
GetEnvironmentVariable Method
GetFileDropList Method
GetFileInfo Method
GetFiles Method
GetImage Method
GetName Method
GetParentPath Method
GetTempFileName Method
GetText Method
GetValue Method
GmtTime Property
HasFieldsEnclosedInQuotes Property
Info Object (My.Application)
Info Object (My.Computer)
InitializeWithWindowsUser Method
InstalledUICulture Property
IsAuthenticated Property
IsAvailable Property
IsInRole Method
IsNetworkDeployed Property
Keyboard Object

LineNumber Property
LoadedAssemblies Property
LocalMachine Property
LocalTime Property
Log Object (My)
Log Object (My.Application)
MinimumSplashScreenDisplayTime Property
Mouse Object
MoveDirectory Method
MoveFile Method
My Namespace
MyDocuments Property
MyMusic Property
MyPictures Property
Name Property (My.Computer)
Name Property (My.User)
Network Object
NetworkAvailabilityChanged Event (My.Application)
NetworkAvailabilityChanged Event (My.Computer.Network)
NumLock Property
OpenForms Property
OpenSerialPort Method
OpenTextFieldParser Method
OpenTextFileReader Method
OpenTextFileWriter Method
OSFullName Property
OSPlatform Property
OSVersion Property
PeekChars Method



This document is created with a trial version of CHM2PDF Pilot

PerformanceData Property
Ping Method
Play Method
PlaySystemSound Method
Ports Object
ProductName Property
ProgramFiles Property
Programs Property
ReadAllBytes Method
ReadAllText Method
ReadFields Method
ReadLine Method
ReadToEnd Method
Registry Object
RenameDirectory Method
RenameFile Method
Request Object
Resources Object
Response Object
Run Method
SaveMySettingsOnExit Property
Screen Property
ScrollLock Property
SendKeys Method
SerialPortNames Property
SetAudio Method
SetData Method

SetDataObject Method
SetDelimiters Method
SetFieldWidths Method
SetFileDropList Method
SetImage Method
SetText Method
Settings Object
SetValue Method
ShiftKeyDown Property
Shutdown Event
SpecialDirectories Object
SplashScreen Property
StackTrace Property
Startup Event
StartupNextInstance Event
Stop Method
Temp Property
TextFieldParser Object
TextFieldType Property
TickCount Property
Title Property
TotalPhysicalMemory Property
TotalVirtualMemory Property
TraceSource Property
Trademark Property
TrimWhiteSpace Property


This document is created with a trial version of CHM2PDF Pilot


TrimWhiteSpace Property
UICulture Property
UnhandledException Event
UploadFile Method
User Object
Users Property
Version Property
WebServices Object
WheelExists Property
WheelScrollLines Property
WorkingSet Property
WriteAllBytes Method
WriteAllText Method
WriteEntry Method
WriteException Method
Part III: Appendixes
Appendix A. Language Elements by Category
Section A.1. Array Handling
Section A.2. Clipboard
Section A.3. Collection Objects
Section A.4. Common Dialogs
Section A.5. Conditional Compilation
Section A.6. Conversion
Section A.7. Date and Time
Section A.8. Debugging
Section A.9. Declaration
Section A.10. Error Handling
Section A.11. File System
Section A.12. Financial
Section A.13. Information

Section A.14. Input/Output
Section A.15. Integrated Development Environment
Section A.16. Interaction
Section A.17. Mathematics
Section A.18. Program Structure and Flow
Section A.19. Programming
Section A.20. Registry
Section A.21. String Manipulation
Appendix B. Namespace Hierarchy
Section B.1. 'My' Namespace Hierarchy
Section B.2. System Namespace Hierarchy
Appendix C. Constants and Enumerations
Section C.1. Visual Basic Intrinsic Constants
Section C.2. ControlChars Class
Section C.3. Visual Basic Enumerations
Appendix D. What's New and Different in Visual Basic .NET 2002
Section D.1. Language Changes in VB.NET 2002
Section D.2. Changes to Programming Elements
Section D.3. Obsolete Programming Elements
Section D.4. Structured Exception Handling
Section D.5. Changes in Object Orientation
Appendix E. What's New and Different in Visual Basic .NET 2003
Section E.1. Language Changes in VB.NET 2003


This document is created with a trial version of CHM2PDF Pilot

Appendix F. What's New and Different in Visual Basic 2005
Section F.1. Enhancements of Existing Functionality
Section F.2. The 'My' Namespace

Section F.3. Other New Features
Appendix G. VB 6 Language Elements No Longer Supported
Appendix H. The Visual Basic Command-Line Compiler
Section H.1. Compiler Basics
Section H.2. Command-Line Switches
Section H.3. Using a Response File
Section H.4. Conditional Compilation Constants
About the Authors
Colophon
Index


This document is created with a trial version of CHM2PDF Pilot


Visual Basic 2005 in a Nutshell
by Tim Patrick, Steven Roman, Ron Petrusha, and Paul Lomax
Copyright © 2006 O'Reilly Media, Inc. All rights reserved.
Printed in the United States of America.
Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available
for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800)
998-9938 or
Editor:

Jeff Pepper

Production Editor:

Darren Kelly


Copyeditor:

Chris Downey

Proofreader:

Genevieve Rajewski

Indexer:

Johnna VanHoose Dinse

Cover Designer:

Pam Spremulli

Interior Designer:

David Futato

Illustrators:

Robert Romano, Jessamyn Read, and Lesley Borash

Printing History:
August 2001:

First Edition.


April 2002:

Second Edition.

January 2006:

Third Edition.

Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc.
The In a Nutshell series designations, Visual Basic 2005 in a Nutshell, Third Edition, the image of a catfish, and related
trade dress are trademarks of O'Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.
Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a trademark claim, the
designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
ISBN: 0-596-10152-X
[M]


This document is created with a trial version of CHM2PDF Pilot


Preface
Microsoft Visual Basic began its life back in 1991 as a kind of amalgamation of Microsoft's QBasic programming
language and a graphical interface design program developed in part by Alan Cooper. Since then, it has become one of
the most popular programming languages in the world.
The 10th anniversary of Visual Basic coincided with the announcement of Microsoft's new .NET platform, and with it a
totally revised and revamped version of Visual Basic named "Visual Basic .NET." With the initial release in 2002, the
language was streamlined and modernized, and many old "compatibility" elements were dropped from the language.

Since that first release, VB.NET has been enhanced and improved through two more general releases (in 2003 and
2005).
Pre-.NET versions of VB included a "good try" implementation of standard object-oriented features, but they often came
up short. Teamed with .NET, Visual Basic is now a fully object-oriented programming (OOP) language, with the inclusion
of the long sought-after class inheritance feature, as well as other OOP elements. The 2005 release adds operator
overloading to the language, something that was absent in the initial .NET version.
Before .NET, Microsoft's Component Object Model (COM) technology played a significant role in application
development, especially when it became part of the foundation of Visual Basic 4.0. With the advent of .NET, COM
begins to take its exit from the Windows programming stage, as .NET includes a new namespace-based component
integration system. This is somewhat unfortunate, since Visual Basic developers have a lot of time and source code
invested in COM components. As great as COM was, it was also complex, and there were numerous compatibility issues
when sharing components between Visual Basic, Visual C++, and other languages that either produced or consumed
these "ActiveX" libraries. All core compatibility issues are banished with .NET, and although you can still take advantage
of your substantial investment in COM components through .NET's "interop" features, the enhancements available
through .NET will certainly draw all developers eventually to abandon the COM system.
For developers who have made the switch from .NET, the best news of all is that Visual Basic is now an "equal player"
with other languages, in terms of programming power and accessibility of Windows features and services. In the past,
Visual Basic served as a "wrapper" that simplified and hid much of the complexity of Windows and its Application
Programming Interface (API). Now, Visual Basic programmers have full and easy access to all features of the .NET and
Windows platforms, just as Visual C++ and C# programmers do.
The extensive changes to the language and the introduction of the .NET platform make a reference guide to the Visual
Basic language more essential than ever. At the same time, they make it easy to delineate this book's subject matter.
This is a book that focuses on the language elements of .NET-powered Visual Basicon its statements, functions,
procedures, directives, and objects.
This book provides essential information on the Visual Basic language for the .NET platform, but there are some things
this book is not:
It is not a reference guide to Visual Basic for Applications (VBA), the programming language used in all of the
major applications in the Microsoft Office suite, as well as in dozens of other third-party applications. VBA
served as the core programming language in earlier versions of Visual Basic. However, VBA is not the
programming language for the .NET versions of Visual Basic. Microsoft Office Version 12 (not named as of this

writing) will include Visual Studio Tools for Applications (VSTA), a new .NET replacement for VBA.
It is not a reference guide to the .NET Framework Class Library. The Framework Class Library is discussed in
these pages, and a number of its classes and their members are documented in this book's reference section.
But that documentation just scratches the surface; the Framework Class Library consists of about 200
namespaces (one of which, incidentally, is Microsoft.VisualBasic, the namespace that defines many features of
the Visual Basic language), several thousand types (including classes, interfaces, delegates, and enumerations),
and an enormous number of members. In selecting the .NET Framework classes to document in this book,
we've tried to focus on .NET elements that replace commonly used features in pre-.NET versions of Visual Basic,
as well as on .NET elements that expand and enhance the productivity of Visual Basic developers.
It is not a reference guide to the attributes that you can apply to program elements. Chapter 9 introduces
attribute-based programming, and there are entries for important language-based attributes in the reference
section. But with hundreds of attributes available in the .NET Framework Class Library, only language-related
attributes and the general-purpose attributes VB developers are most likely to use are documented in this book.
It is not a guide to developing full applications or components using Visual Basic or .NET. The text includes
simple code fragments that illustrate relevant syntax and code usage, to demonstrate how a language element
works. But it doesn't show you the big-picture activities, such as how to use the Windows Forms package to
build a Windows application, how to develop a web application using ASP.NET, or how to implement a web
service.


This document is created with a trial version of CHM2PDF Pilot


Why Another Visual Basic Book?
Each major release of Visual Basic leaves shelves full of tutorial and training books in its wake. The 2005 release of
Visual Basic is no exception, especially since Microsoft expects adoption of Visual Basic on the .NET platform to
dramatically increase with this edition. The majority of VB books assume that you're a complete novice and slowly
introduce you to basic concepts such as variables, arrays, and looping structures.
This is a different kind of book. It is a detailed, professional reference to the Visual Basic languagea reference that you
can use to jog your memory about a particular language element or a particular parameter. It will come in handy when

you need to review the rules for a particular language element, or when you want to check that there isn't some
"gotcha" you've overlooked with a particular language feature.
In addition, this book serves as a valuable reference for VB 6 programmers who are upgrading to .NET and for existing
.NET programmers who need to know about specific differences found in each subsequent release of the Visual Basic
language. To this end, we have devoted considerable space to the extensive language differences between VB 6 and
VB.NET 2002, and the versions beyond. For each relevant language entry in the large reference chapter (Chapter 12),
we have included a "Version Differences" section that details the usage changes for the language element between VB 6
and the 2002, 2003, and 2005 releases of Visual Basic.


This document is created with a trial version of CHM2PDF Pilot


Who This Book Is For
Just like any reference, this book will be useful to many types of readers:
Developers who have used previous versions of Visual Basic
Developers who are new to Visual Basic, but who have been developing applications in other programming
languages, such as C++
Those who are learning VB as their first language and would like to have a definitive language reference on
their shelf

Readers New to Visual Basic
If you are new to the Visual Basic language, then you will want to pay particular attention to the first part of the book,
which discusses many important areas of programming in .NET with Visual Basic, including variables, data types, the
basic principles of object-oriented programming, and error-handling techniques.

VB and VBScript Developers New to .NET
Some critics have argued that with .NET, Microsoft has introduced an entirely new VB language, separate and distinct
from VB 6. While we wouldn't go quite that far, we do recognize that beyond the syntax changes, the new .NET
platform brings a paradigm shift that affects the way we think about application development. As a VB 6 or VBScript

developer new to .NET, you may find yourself in a position similar to that of a developer who is new to all flavors of
Visual Basic.
This book will ease your transition to .NET from earlier versions of Visual Basic. In particular, the first 11 chapters of the
book offer a rapid introduction to VB and .NET and to their new features. Appendix D discusses many of the major
language changes between VB 6 and VB.NET 2002, while Appendix G lists VB 6 language elements that are no longer
supported in .NET editions. The "Version Differences" entries in Chapter 12 also provide support for your migration to
.NET.

Existing .NET Developers
Early adopters of Visual Basic for the .NET platform have been vindicated, as the Windows development world has
followed their lead in droves. And while programmers coming fresh into the language with the 2005 release will
experience a completely new level of software development, the update introduces changes that keep VB a moving
target even for experienced .NET programmers. That's why Visual Basic 2005 in a Nutshell includes Appendix E and
Appendix F, which document the major changes introduced into the language since the initial 2002 release. You will also
find some use for the "Version Differences" entries in Chapter 12.


This document is created with a trial version of CHM2PDF Pilot


How This Book Is Structured
Visual Basic 2005 in a Nutshell is divided into three parts. Part I, The Basics, is an introduction to the main features and
concepts of Visual Basic programming. If you are new to Visual Basic or .NET, this part of the book is essential reading.
It is divided into the following chapters:

Chapter 1, Introduction
In this chapter, you will read how Visual Basic has been transformed into its .NET variation and get some sense
of how and why the .NET version is different from previous editions of Visual Basic.

Chapter 2, The .NET Framework: General Concepts

This chapter surveys some of the features of the .NET Framework that most impact the VB developer. These
include namespaces, the Common Language Runtime (CLR), and assemblies.

Chapter 3, Introduction to Object-Oriented Programming
This chapter discusses the basic concepts of object-oriented programming and shows how to implement VB's
object-oriented features in your code.

Chapter 4, Variables and Data Types
This chapter looks at the standard Visual Basic data types and how to use them. Behind the scenes, VB takes
advantage of the .NET Framework's Common Type System, so the chapter also examines the .NET data types
and the way in which VB wraps these data types.

Chapter 5, Operators
This chapter surveys the operators you use to manipulate data in VB. It also introduces operator overloading, a
new feature with the 2005 release.

Chapter 6, Program Structure
This chapter discusses the entry points that allow the .NET runtime to execute your code and shows how to
structure the code in a Visual Basic program.

Chapter 7, The .NET Framework Class Library
The .NET Framework Class Library (FCL) replaces portions of the Win32 API, as well as many of the individual
object models familiar to pre-.NET VB programmers. This chapter offers a fast-paced overview of the
Framework Class Library and some of its features.

Chapter 8, Delegates and Events
While handling events was more or less automatic in previous versions of VB, events in .NET are "wired"
through the source code itself. This chapter shows how events work and what they mean to you as a
programmer.


Chapter 9, Attributes
The .NET Framework supports attributes, an extensible mechanism that lets you "decorate" program elements
(such as classes and class members) with tags that describe or alter the use of those elements. Attributes are
stored in the assembly's "metadata" and can be used to influence the compiler, the design time environment, or
the runtime environment. This chapter explains attributes and shows you how to use and define them.

Chapter 10, Generics


This document is created with a trial version of CHM2PDF Pilot

Chapter 10, Generics
Visual Basic 2005 includes a new feature called "generics" that lets you better control the objects managed by
other general-use classes. This chapter describes the feature and provides examples for its use.

Chapter 11, Error Handling in Visual Basic
Visual Basic now offers two techniques for error handling. The first, which uses the OnError statement, is termed
unstructured error handling and is a traditional part of VB. The second, which uses the try...Catch...Finally
construct, is termed structured exception handling and is new to the .NET implementation. In this chapter, we'll
show you how to use both.
Part II of the book thoroughly details all the functions, statements, directives, objects, and object members that make
up the Visual Basic language.

Chapter 12, The Language Reference
This chapter provides syntax and usage information for all major VB language features, plus information on
some of the more useful .NET Framework features that are not officially part of the VB language.

Chapter 13, The 'My' Reference
This chapter fully documents the My Namespace feature, a convenient new library introduced with Visual Basic
2005.

The third and final section, Part III, consists of the following appendixes:

Appendix A, Language Elements by Category
A listing of all VB functions, statements, and major keywords, grouped by category.

Appendix B, Namespace Hierarchy
A hierarchical listing of the .NET namespaces from System on down, plus the hierarchy of the Visual Basic My
Namespace feature.

Appendix C, Constants and Enumerations
A list of VB intrinsic constants, as well as VB enumerations and their members.

Appendix D, What's New and Different in Visual Basic .NET 2002
A discussion of language changes from VB 6 to Visual Basic .NET 2002.

Appendix E, What's New and Different in Visual Basic .NET 2003
A discussion of language changes introduced with Visual Basic .NET 2003 and the .NET Framework, Version 1.1.

Appendix F, What's New and Different in Visual Basic 2005
A discussion of language changes introduced with Visual Basic 2005 and the .NET Framework, Version 2.0.

Appendix G, VB 6 Language Elements No Longer Supported
A list of the language elements that have dropped out of the Visual Basic language as a result of its transition to
the .NET Framework.

Appendix H, The Visual Basic Command-Line Compiler
Visual Basic includes a command-line compileryou can actually use Notepad as your primary "development
environment" for Visual Basic and use the compiler to compile your code. This Appendix documents the
operation of the Visual Basic command-line compiler and its options.



This document is created with a trial version of CHM2PDF Pilot



This document is created with a trial version of CHM2PDF Pilot


About the Third Edition
The first two editions of Visual Basic 2005 in a Nutshell (which were both named VB.NET Language in a Nutshell)
focused solely on the initial release of Visual Basic .NET (the 2002 release) and related .NET features (the .NET
Framework, Version 1.0). This third edition incorporates all new and significant features added in both the 2003 and
2005 releases of Visual Basic. Part I, The Basics, has been reorganized to better support the learning process for
programmers new to Visual Basic and .NET concepts in general. The largest change is the addition of two new chapters:
Generics (Chapter 10) and The 'My' Reference (Chapter 13). Chapter 5, Operators, is also a new chapter, although it
existed in the second edition as an appendix. While the third edition focuses on Visual Basic 2005, it is still useful with
earlier releases of VB.NET; all feature differences between the various releases of Visual Basic for .NET are clearly
marked throughout the book.
When the first release of Visual Basic for .NET appeared in 2002, the official name of the product was "Visual Basic
.NET," a naming convention that was retained in the 2003 release. However, beginning with the 2005 release, the
language name has officially reverted back to plain "Visual Basic." As this book focuses on the 2005 release of Visual
Basic, this name change is reflected throughout the text. In most cases, the meaning of "Visual Basic" or "VB" will be
clear through context, but in situations where confusion may exist, the text will specify the version discussed. Because
Appendixes D and E specifically discuss the 2002 and 2003 releases of Visual Basic, they still include references to
"Visual Basic .NET" and "VB.NET." There are also a few other places in the text where such usage is warranted.


This document is created with a trial version of CHM2PDF Pilot



Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and
documentation. You do not need to contact O'Reilly for permission unless you're reproducing a significant portion of the
code. For example, writing a program that uses several chunks of code from this book does not require permission.
Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by
citing this book and quoting example code does not require permission. Incorporating a significant amount of example
code from this book into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For
example: "Visual Basic 2005 in a Nutshell, by Tim Patrick, Steven Roman, Ron Petrusha, and Paul Lomax. Copyright
2006 O'Reilly Media, Inc., 0-596-10152-X."
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact the
publisher at


This document is created with a trial version of CHM2PDF Pilot


Conventions Used in This Book
Throughout this book, we've used the following typographic conventions:

Constant Width
Constant width in body text indicates a language construct, such as a VB keyword (like For or Do While), or a
named element from an adjacent block of sample source code. Members of the Microsoft.VisualBasic
namespace usually appear in constant-width text as well. Code fragments and code examples appear
exclusively in constant-width text. In syntax statements and prototypes, text set in constant width indicates
such language elements as the function or procedure name and any invariable elements required by the syntax.

Constant Width Italic

In syntax statements and code prototypes, constant width italic indicates replaceable parameters.


Italic
Italicized words in the text indicate intrinsic or user-defined namespaces, classes, functions, procedures, and
other member names (except for those in the Microsoft.VisualBasic namespace). Many system elements, such
as paths and filenames, are also italicized. In addition, URLs and email addresses are italicized. Finally, italics
are employed the first time a term is used or defined.
Code prototypes use a simplified Backus-Naur notation, presenting all optional elements of the syntax in square
brackets ([ and ]). Curly braces ({ and }) surround a set of choices from which one must be chosen. The individual
choices, whether required or optional, are delimited by a vertical bar (|).
This icon indicates a note, which is an important aside to its nearby text.

This icon indicates a warning.


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×