VB . NET Language in a Nutshell Steven Roman Ron Petrusha Paul Lomax Publisher: O’Reilly First Edition August 2001 ISBN: 0-596-00092-8, 654 pages Need to make sense of the many changes to Visual Basic for the new . NET platform? VB . NET Language in a Nutshell introduces the important aspects of the language and explains the . NET framework. An alphabetical reference covers the functions, statements, directives, objects, and object members that make up the VB . NET language. To ease the transition, each language element includes a “VB . NET/VB 6 Differences” section. Preface……………………………………………………………………………………………………………….. 14 Why Another VB Book? ………………………………………………………………………………. 26 Who This Book Is For………………………………………………………………………………….. 26 Readers New to Visual Basic………………………………………………………………….. 26 VB and VBScript Developers New to VB . NET…………………………………….. 6 Existing VB . NET Developers …………………………………………………………………. 27 How This Book Is Structured …………………………………………………………………….. 27 The Format of the Language Reference ………………………………………………. 28 Conventions Used in This Book…………………………………………………………………. 29 How to Contact Us ………………………………………………………………………………………. 0 Acknowledgments ……………………………………………………………………………………….. 30 Part I: The Basics ……………………………………………………………………………………………….. 33 Chapter 1. Introduction ……………………………………………………………………………………….. 33 1. 1 Why VB . NET? ……………………………………………………………………………………….. 34 1. 2 What Is VB . NET? …………………………………………………………………………………. 7 1. 2. 1 Object Orientation…………………………………………………………………………. 37 1. 2. 2 A Common Type System ……………………………………………………………… 38 1. 2. 3 Access to System Services: The Framework Class Library …… 39 1. 2. 4 A Common Runtime Environment ……………………………………………… 41 1. 3 What Can You Do with VB . NET?……………………………………………………….. 42 Chapter 2. Variables and Data Types…………………………………………………………………. 3 2. 1 Variables ………………………………………………………………………………………………… 43 2. 1. 1 Variable Scope……………………………………………………………………………….. 43 2. 1. 2 Variable Lifetime ……………………………………………………………………………. 45 2. 2 Declaring Variables and Constants……………………………………………………. 47 2. 3 Data Types …………………………………………………………………………………………….. 8 2. 3. 1 Value and Reference Types …………………………………………………………. 49 2. 3. 2 VB Data Types: A Summary ……………………………………………………….. 51 2. 3. 3 Simple Data Types in Visual Basic……………………………………………… 54 2. 3. 4 Data Type Conversion ………………………………………………………………….. 62 2. 4 Arrays……………………………………………………………………………………………………… 64 2. 4. Definition of Array…………………………………………………………………………. 64 2. 4. 2 Dimension of an Array………………………………………………………………….. 64 2. 4. 3 Size of an Array …………………………………………………………………………….. 64 2. 4. 4 Arrays in VB . NET ………………………………………………………………………….. 65 2. 5 Object Variables and Their Binding …………………………………………………… 67 2. . 1 Late Binding Versus Early Binding……………………………………………… 68 2. 6 The Collection Object …………………………………………………………………………… 69 2. 7 Parameters and Arguments………………………………………………………………… 70 2. 7. 1 Passing Arguments ……………………………………………………………………….. 70 2. 7. 2 Passing Objects ……………………………………………………………………………… 71 2. 7. Optional Arguments………………………………………………………………………. 73 2. 7. 4 ParamArray …………………………………………………………………………………….. 73 Chapter 3. Introduction to Object-Oriented Programming …………………………………… 75 3. 1 Why Learn Object-Oriented Techniques? ………………………………………… 75 2 3. 2 Principles of Object-Oriented Programming …………………………………….. 75 3. 2. 1 Abstraction ……………………………………………………………………………………… 5 3. 2. 2 Encapsulation …………………………………………………………………………………. 76 3. 2. 3 Interfaces ………………………………………………………………………………………… 77 3. 3 Classes and Objects……………………………………………………………………………… 79 3. 3. 1 Class Modules in VB . NET …………………………………………………………….. 79 3. 3. 2 Class Members ……………………………………………………………………………….. 79 3. 3. 3 The Public Interface of a VB .
NET Class ……………………………………. 81 3. 3. 4 Objects …………………………………………………………………………………………….. 81 3. 3. 5 Properties………………………………………………………………………………………… 82 3. 3. 6 Instance and Shared Members……………………………………………………. 83 3. 3. 7 Class Constructors…………………………………………………………………………. 84 3. 3. 8 Finalize, Dispose, and Garbage Collection ………………………………… 5 3. 4 Inheritance …………………………………………………………………………………………….. 86 3. 4. 1 Permission to Inherit …………………………………………………………………….. 88 3. 4. 2 Overriding ……………………………………………………………………………………….. 88 3. 4. 3 Rules of Inheritance………………………………………………………………………. 89 3. 4. 4 MyBase, MyClass, and Me ……………………………………………………………. 9 3. 5 Interfaces, Abstract Members, and Classes …………………………………….. 91 3. 5. 1 Interfaces Revisited ………………………………………………………………….. ….. 93 3. 6 Polymorphism and Overloading …………………………………………………………. 93 3. 6. 1 Overloading …………………………………………………………………………………….. 93 3. 6. 2 Polymorphism…………………………………………………………………………………. 94 3. Scope and Accessibility in Class Modules…………………………………………. 95 Chapter 4. The . NET Framework: General Concepts………………………………………….. 97 4. 1 Namespaces …………………………………………………………………………………………… 97 4. 2 Common Language Runtime (CLR), Managed Code, and Managed Data………………………………………………………………………………………………………………… 97 4. 3 Managed Execution ………………………………………………………………………………. 8 4. 4 Assemblies……………………………………………………………………………………………… 98 4. 5 Assemblies and VB . NET ……………………………………………………………………. 100 Chapter 5. The . NET Framework Class Library…………………………………………………. 103 5. 1 The System Namespace…………………………………………………………………….. 104 5. 1. 1 Data Type Conversion…………………………………………………………………. 104 5. 1. The Array Class…………………………………………………………………………….. 105 5. 1. 3 The Math Class……………………………………………………………………………… 106 5. 1. 4 The String Class …………………………………………………………………………… 107 5. 2 Other Namespaces ………………………………………………………………….. …………. 108 5. 2. 1 System. Collections ………………………………………………………………………. 10 5. 2. 2 System. Data …………………………………………………………………………………. 110 5. 2. 3 System. IO……………………………………………………………………………………… 111 5. 2. 4 System. Text. RegularExpressions ……………………………………………… 111 5. 2. 5 System. Windows. Forms ……………………………………………………………… 113 Chapter 6. Delegates and Events ……………………………………………………………………… 15 6. 1 Delegates ……………………………………………………………………………………………… 115 6. 1. 1 Using a Delegate to Call a Method……………………………………………. 116 6. 1. 2 Using a Delegate as a Function Pointer …………………………………… 117 3 6. 2 Events and Event Binding …………………………………………………………………. 118 6. 2. 1 Control-Related Events ………………………………………………………………. 119 6. 2. WithEvents ……………………………………………………………………………………. 119 6. 2. 3 AddHandler …………………………………………………………………………………… 120 Chapter 7. Error Handling in VB . NET ………………………………………………………………. 123 7. 1 Error Detection and Error Handling…………………………………………………. 123 7. 2 Runtime Error Handling …………………………………………………………………….. 124 7. 2. 1 Unstructured Error Handling …………………………………………………….. 124 7. 2. 2 Structured Exception Handling …………………………………………………. 127 7. 3 Dealing with Logical Errors……………………………………………………………….. 131 7. 3. 1 Detecting Logical Errors……………………………………………………………… 131 7. 3. 2 Where to Handle a Logical Error ………………………………………………. 132 7. 4 Error Constants …………………………………………………………………………………… 33 Part II: Reference ……………………………………………………………………………………………… 135 Chapter 8. The Language Reference …………………………………………………………….. 135 #Const Directive…………………………………………………………………………………….. 137 #If… Then… #Else Directive …………………………………………………………………. 139 #Region… #End Region Directive ……………………………………………………….. 41 Abs Function……………………………………………………………………………………………. 141 Acos Function………………………………………………………………………………………….. 143 AddHandler Statement………………………………………………………………………….. 143 AddressOf Operator……………………………………………………………………………….. 144 AppActivate Procedure ………………………………………………………………………….. 45 Application Class…………………………………………………………………………………….. 147 Application. CompanyName Property ………………………………………………….. 148 Application. DoEvents Method ………………………………………………………………. 149 Application. ExecutablePath Property………………………………………………….. 150 Application. ProductName Property……………………………………………………… 151 Application. ProductVersion Property ………………………………………………….. 52 Array Class………………………………………………………………………………………………. 152 Array. BinarySearch Method …………………………………………………………………. 153 Array. Copy Method ………………………………………………………………………………… 156 Array. IndexOf Method …………………………………………………………………………… 158 Array. LastIndexOf Method……………………………………………………………………. 159 Array.
Reverse Method …………………………………………………………………………… 161 Array. Sort Method………………………………………………………………………………….. 162 Asc, AscW Functions ……………………………………………………………………………… 164 Asin Function…………………………………………………………………………………………… 166 Atan Function………………………………………………………………………………………….. 67 See Also …………………………………………………………………………………………………… 168 Atan2 Function ……………………………………………………………………………………….. 168 Beep Procedure ………………………………………………………………………………………. 169 Call Statement………………………………………………………………………………………… 170 CallByName Function …………………………………………………………………………….. 72 CBool Function………………………………………………………………………………………… 174 CByte Function ……………………………………………………………………………………….. 175 CChar Function ……………………………………………………………………………………….. 176 4 CDate Function ……………………………………………………………………………………….. 177 CDbl Function ………………………………………………………………………………………….. 78 CDec Function …………………………………………………………………………………………. 179 Ceiling Function ………………………………………………………………………………………. 180 ChDir Procedure ……………………………………………………………………………………… 181 ChDrive Procedure………………………………………………………………………………….. 182 Choose Function ……………………………………………………………………………………… 84 Chr, ChrW Functions………………………………………………………………………………. 185 CInt Function …………………………………………………………………………………………… 187 Class Statement ……………………………………………………………………………………… 188 Clipboard Class ……………………………………………………………………………………….. 190 Clipboard. GetDataObject Method ………………………………………………………… 90 Clipboard. SetDataObject Method ………………………………………………………… 192 CLng Function………………………………………………………………………………………….. 192 CObj Function………………………………………………………………………………………….. 194 Collection Class……………………………………………………………………………………….. 195 Collection. Add Method …………………………………………………………………………… 98 Collection. Count Property……………………………………………………………………… 199 Collection. Item Method …………………………………………………………………………. 200 Collection. Remove Method……………………………………………………………………. 202 ColorDialog Class ……………………………………………………………………………………. 203 Command Function ………………………………………………………………………………… 05 Const Statement …………………………………………………………………………………….. 207 Cos Function ……………………………………………………………………………………………. 208 Cosh Function………………………………………………………………………………………….. 209 CreateObject Function …………………………………………………………………………… 210 CShort Function………………………………………………………………………………………. 12 CSng Function …………………………………………………………………………………………. 214 CStr Function…………………………………………………………………………………………… 215 CType Function ………………………………………………………………….. …………………… 216 CurDir Function……………………………………………………………………………………….. 218 DateAdd Function……………………………………………………………………………………. 19 DateDiff Function ……………………………………………………………………………………. 221 DatePart Function …………………………………………………………………………………… 224 DateSerial Function………………………………………………………………………………… 226 DateString Property ……………………………………………………………………………….. 228 DateValue Function ………………………………………………………………………………… 29 Day Function……………………………………………………………………………………………. 230 DDB Function…………………………………………………………………………………………… 231 Debug Class …………………………………………………………………………………………….. 233 Debug. Assert Method…………………………………………………………………………….. 234 Debug. AutoFlush Property ……………………………………………………………………. 35 Debug. Close Method………………………………………………………………………………. 235 Debug. Flush Method ………………………………………………………………………………. 236 Debug. Indent Method ……………………………………………………………………………. 236 Debug. IndentLevel Property…………………………………………………………………. 237 Debug. IndentSize Property…………………………………………………………………… 237 5
Debug. Listeners Property……………………………………………………………………… 238 Debug. Unindent Method ……………………………………………………………………….. 238 Debug. Write Method ……………………………………………………………………………… 239 Debug. WriteIf Method …………………………………………………………………………… 240 Debug. WriteLine Method ………………………………………………………………………. 241 Debug.
WriteLineIf Method ……………………………………………………………………. 242 Declare Statement …………………………………………………………………………………. 243 Delegate Statement ………………………………………………………………………………. 248 DeleteSetting Procedure……………………………………………………………………….. 249 Dim Statement ……………………………………………………………………………………….. 51 Dir Function …………………………………………………………………………………………….. 256 Directory Class ……………………………………………………………………………………….. 259 Directory. CreateDirectory Method………………………………………………………. 260 Directory. Delete Method……………………………………………………………………….. 261 Directory. Exists Method………………………………………………………………………… 262 Directory.
GetCreationTime Method…………………………………………………….. 263 Directory. GetDirectories Method…………………………………………………………. 263 Directory. GetDirectoryRoot Method……………………………………………………. 265 Directory. GetFiles Method…………………………………………………………………….. 266 Directory. GetFileSystemEntries Method…………………………………………….. 267 Directory. GetLogicalDrives Method …………………………………………………….. 68 Directory. GetParent Method ………………………………………………………………… 269 Directory. Move Method …………………………………………………………………………. 270 Do… Loop Statement……………………………………………………………………………… 271 E Field ………………………………………………………………………………………………………. 274 End Statement …………………………………………………………………………………….. 74 Enum Statement…………………………………………………………………………………….. 276 Environ Function …………………………………………………………………………………….. 278 EOF Function …………………………………………………………………………………………… 280 Erase Statement …………………………………………………………………………………….. 281 Erl Property……………………………………………………………………………………………… 82 Err Object ………………………………………………………………………………………………… 283 Err. Clear Method…………………………………………………………………………………….. 284 Err. Description Property ……………………………………………………………………….. 285 Err. GetException Method………………………………………………………………………. 286 Err. HelpContext Property ……………………………………………………………………… 88 Err. HelpFile Property……………………………………………………………………………… 289 Err. LastDLLError Property…………………………………………………………………….. 290 Err. Number Property……………………………………………………………………………… 291 Err. Raise Method ……………………………………………………………………………………. 293 Err. Source Property……………………………………………………………………………….. 95 Error Statement ……………………………………………………………………………………… 295 ErrorToString Function ………………………………………………………………………….. 296 Event Statement…………………………………………………………………………………….. 297 Exception Class ………………………………………………………………………………………. 299 Exit Statement………………………………………………………………………………………… 02 Exp Function……………………………………………………………………………………………. 303 6 File Class ………………………………………………………………………………………………….. 304 File. Exists Method…………………………………………………………….. ……………………. 305 FileAttr Function ……………………………………………………………………………………… 306 FileClose Procedure ………………………………………………………………………………… 07 FileCopy Procedure…………………………………………………………………………………. 308 FileDateTime Function……………………………………………………………………………. 309 FileGet, FileGetObject Procedures……………………………………………………….. 310 FileLen Function………………………………………………………………………………………. 312 FileOpen Procedure ………………………………………………………………………………… 13 FilePut, FilePutObject Procedures………………………………………………………… 316 FileWidth Procedure ……………………………………………………………………………….. 318 Filter Function………………………………………………………………………………………….. 319 Fix Function……………………………………………………………………………………………… 321 Floor Function………………………………………………………………………………………….. 22 FontDialog Class……………………………………………………………………………………… 323 For… Next Statement……………………………………………………………………………… 325 For Each… Next Statement……………………………………………………………………. 327 Format Function ……………………………………………………………………………………… 329 FormatCurrency, FormatNumber, FormatPercent Functions………….. 341 FormatDateTime Function ………………………………………………………………….. .. 343 FreeFile Function …………………………………………………………………………………….. 345 Friend Keyword……………………………………………………………………………………….. 345 Function Statement………………………………………………………………………………… 346 FV Function………………………………………………………………………………………………. 350 Get Statement…………………………………………………………………………………………. 52 GetAllSettings Function …………………………………………………………………………. 353 GetAllSettings Function …………………………………………………………………………. 355 GetAttr Function ……………………………………………………………………………………… 357 GetObject Function…………………………………………………………………………………. 359 GetSetting Function ……………………………………………………………………………….. 61 GetTimer Function ………………………………………………………………………………….. 363 GoTo Statement ……………………………………………………………………………………… 364 Handles Keyword ……………………………………………………………………………………. 365 Hashtable Class ………………………………………………………………………………………. 366 Hashtable. Add Method…………………………………………………………………………… 368 Hashtable.
Clear Method ………………………………………………………………………… 369 Hashtable. ContainsKey Method……………………………………………………………. 370 Hashtable. ContainsValue Method ………………………………………………………… 371 Hashtable. CopyTo Method…………………………………………………………………….. 371 Hashtable. Count Property …………………………………………………………………….. 372 Hashtable. Item Property……………………………………………………………………….. 73 Hashtable. Keys Property……………………………………………………………………….. 374 Hashtable. Remove Method …………………………………………………………………… 375 Hashtable. Values Property ……………………………………………………………………. 376 Hex Function ……………………………………………………………………………………………. 377 Hour Function ………………………………………………………………………………………….. 78 IDataObject Interface ……………………………………………………………………………. 379 7 IDataObject. GetData Method ………………………………………………………………. 379 IDataObject. GetDataPresent Method …………………………………………………. 381 IDataObject. GetFormats Method ………………………………………………………… 383 IEEERemainder Function ………………………………………………………………………. 384 If… Then…
Else Statement ……………………………………………………………………. 384 IIf Function ………………………………………………………………….. …………………………. 389 Implements Keyword…………………………………………………………………………….. 390 Implements Statement …………………………………………………………………………. 391 Imports Statement ………………………………………………………………………………… 93 Inherits Statement…………………………………………………………………………………. 394 Input Procedure ……………………………………………………………………………………… 395 InputBox Function………………………………………………………………………………….. 397 InputString Function ……………………………………………………………………………… 399 InStr Function …………………………………………………………………………………………. 00 InStrRev Function ………………………………………………………………………………….. 402 Int Function …………………………………………………………………………………………….. 403 Interface Statement ………………………………………………………………………………. 404 IPmt Function………………………………………………………………………………………….. 407 IRR Function……………………………………………………………………………………………. 10 Is Operator………………………………………………………………………………………………. 411 IsArray Function …………………………………………………………………………………….. 412 IsDate Function ………………………………………………………………………………………. 413 IsDBNull Function…………………………………………………………………………………… 414 IsError Function ……………………………………………………………………………………… 15 IsNothing Function…………………………………………………………………………………. 416 IsNumeric Function………………………………………………………………………………… 417 IsReference Function …………………………………………………………………………….. 417 Join Function …………………………………………………………………………………………… 419 Kill Procedure ………………………………………………………………………………………….. 20 LBound Function …………………………………………………………………………………….. 421 LCase Function ……………………………………………………………………………………….. 423 Left Function……………………………………………………………………………………………. 423 Len Function ……………………………………………………………………………………………. 425 Like Operator ………………………………………………………………………………………….. 26 LineInput Function …………………………………………………………………………………. 427 Loc Function ……………………………………………………………………………………………. 429 Lock Procedure ……………………………………………………………………………………….. 430 LOF Function …………………………………………………………………………………………… 431 Log Function ……………………………………………………………………………………………. 32 Log10 Function ……………………………………………………………………………………….. 434 LTrim Function…………………………………………………………… …………………………… 435 Max Function …………………………………………………………………………………………… 436 Me Operator…………………………………………………………………………………………….. 437 Mid Function ……………………………………………………………………………………………. 38 Mid Statement ………………………………………………………………………………………… 440 Min Function ……………………………………………………………………………………………. 441 Minute Function………………………………………………………………………………………. 442 8 MIRR Function …………………………………………………………………………………………. 443 MkDir Procedure ……………………………………………………………………………………… 44 Mod Operator…………………………………………………………………………………………… 445 Module… End Module Statement………………………………………………………….. 446 Month Function ……………………………………………………………………………………….. 447 MonthName Function……………………………………………………………………………… 448 MsgBox Function …………………………………………………………………………………….. 49 MyBase Keyword …………………………………………………………………………………….. 452 MyClass Keyword ……………………………………………………………………………………. 453 Namespace Statement…………………………………………………………………………… 454 Now Property …………………………………………………………………………………………… 455 NPer Function ………………………………………………………………………………………….. 56 NPV Function……………………………………………………………………………………………. 458 Oct Function…………………………………………………………………………………………….. 459 On Error Statement………………………………………………………………………………… 460 OpenFileDialog Class ……………………………………………………………………………… 463 Option Compare Statement ………………………………………………………………….. 66 Option Explicit Statement……………………………………………………………………… 466 Option Strict Statement ………………………………………………………………………… 467 Partition Function……………………………………………………………………………………. 469 Pi Field………………………………………………………………………………………………………. 471 Pmt Function……………………………………………………………………………………………. 72 Pow Function……………………………………………………………………………………………. 473 PPmt Function …………………………………………………………………………………………. 474 Print, PrintLine Procedures……………………………………………………………………. 476 Private Statement…………………………………………………………………………………… 478 Property Statement………………………………………………………….. ……………………. 80 Protected Keyword …………………………………………………………………………………. 485 Public Statement …………………………………………………………………………………….. 485 PV Function………………………………………………………………………………………………. 488 QBColor Function ……………………………………………………………………………………. 490 Queue Class …………………………………………………………………………………………….. 91 Queue. Clear Method ………………………………………………………………………………. 493 Queue. Contains Method ………………………………………………………………………… 493 Queue. CopyTo Method…………………………………………………………………………… 494 Queue. Count Property …………………………………………………………………………… 495 Queue. Dequeue Method………………………………………………………………………… 96 Queue. Enqueue Method ………………………………………………………………………… 497 Queue. Peek Method ……………………………………………………………………………….. 497 Queue. ToArray Method………………………………………………………………………….. 498 RaiseEvent Statement……………………………………………………………………………. 498 Randomize Procedure…………………………………………………………………………….. 00 Rate Function…………………………………………………………………………………………… 501 ReDim Statement …………………………………………………………………………………… 503 Rem Statement……………………………………………………………………………………….. 505 Rename Procedure …………………………………………………………………………………. 506 Replace Function …………………………………………………………………………………….. 07 9 Reset Procedure……………………………………………………………………………………… 509 Resume Statement ………………………………………………………………………………… 510 Return Statement…………………………………………………………………………………… 511 RGB Function…………………………………………………………………………………………… 513 Right Function…………………………………………………………………………………………. 14 RmDir Procedure…………………………………………………………………………………….. 515 Rnd Function …………………………………………………………………………………………… 517 Round Function ………………………………………………………………………………………. 519 RTrim Function ……………………………………………………………………………………….. 520 SaveFileDialog Class ……………………………………………………………………………… 21 SaveSetting Procedure………………………………………………………………………….. 523 ScriptEngine Function……………………………………………………………………………. 524 ScriptEngineBuildVersion Function ……………………………………………………… 525 ScriptEngineMajorVersion Function…………………………………………………….. 526 ScriptEngineMinorVersion Function…………………………………………………….. 527 Return Value……………………………………………………………………………………………. 27 Second Function……………………………………………………………………………………… 528 Seek Function …………………………………………………………………………………………. 528 Seek Procedure ………………………………………………………………………………………. 529 Select Case Statement………………………………………………………………………….. 530 Send, SendWait Methods ……………………………………………………………………… 32 Set Statement ………………………………………………………………………………………… 535 SetAttr Procedure…………………………………………………………………………………… 537 Shadows Keyword………………………………………………………………………………….. 539 Shell Function …………………………………………………………………………………………. 541 Sign Function ………………………………………………………………………………………….. 44 Sin Function…………………………………………………………………………………………….. 545 Sinh Function ………………………………………………………………………………………….. 546 SLN Function …………………………………………………………………………………………… 547 Space Function ……………………………………………………………………………………….. 548 Spc Function……………………………………………………………………………………………. 49 Split Function ………………………………………………………………………………………….. 550 Sqrt Function…………………………………………………………………………………………… 551 Stack Class………………………………………………………………………………………………. 552 Stack. Clear Method ……………………………………………………………………………….. 554 Stack. Contains Method …………………………………………………………………………. 54 Stack. CopyTo Method……………………………………………………………………………. 555 Stack. Count Property…………………………………………………………………………….. 556 Stack. Peek Method ………………………………………………………………………………… 557 Stack. Pop Method ………………………………………………………………………………….. 557 Stack. Push Method ………………………………………………………………………………… 558 Stack.
ToArray Method …………………………………………………………………………… 559 Static Statement…………………………………………………………………………………….. 559 Stop Statement ………………………………………………………………………………………. 562 Str Function …………………………………………………………………………………………….. 563 StrComp Function…………………………………………………………………………………… 64 StrConv Function ……………………………………………………………………………………. 565 10 StrDup Function………………………………………………………………………………………. 567 StrReverse Function……………………………………………………………………………….. 568 Structure… End Structure Statement………………………………………………….. 568 Sub Statement ………………………………………………………………………………………… 70 Switch Function ………………………………………………………………………………………. 574 SYD Function …………………………………………………………………………………………… 575 SyncLock Statement………………………………………………………………………………. 576 SystemTypeName Function ………………………………………………………………….. 577 Tab Function ……………………………………………………………………………………………. 79 Tan Function ……………………………………………………………………………………………. 580 Tanh Function………………………………………………………………………………………….. 581 Throw Statement ……………………………………………………………………………………. 582 TimeOfDay Property ………………………………………………………………………………. 582 Timer Property ………………………………………………………………………………………… 83 TimeSerial Function ……………………………………………………………………………….. 584 TimeString Property……………………………………………………………………………….. 585 TimeValue Function………………………………………………………………………………… 586 Today Property………………………………………………………………………………………… 587 Trim Function…………………………………………………………………………………………… 88 Try… Catch… Finally Statement ……………………………………………………………. 589 TypeName Function ……………………………………………………………………………….. 591 UBound Function …………………………………………………………………………………….. 593 UCase Function ……………………………………………………………………………………….. 594 Unlock Procedure ……………………………………………………………………………………. 94 Val Function …………………………………………………………………………………………….. 596 ValDec Function………………………………………………………………………………………. 597 VarType Function ……………………………………………………………………………………. 598 VbTypeName Function …………………………………………………………………………… 599 Weekday Function ………………………………………………………………………………….. 01 WeekdayName Function………………………………………………………………………… 602 While… End While Statement ……………………………………………………………….. 604 With Statement……………………………………………………………………………………….. 605 WithEvents Keyword………………………………………………………………………………. 606 Write Procedure………………………………………………………….. ………………………….. 08 WriteLine Procedure……………………………………………………………………………….. 609 Year Function…………………………………………………………………………………………… 610 Part III: Appendixes …………………………………………………………………………………………… 613 Appendix A. What’s New and Different in VB . NET …………………………………………… 615 A. 1 Language Changes for VB . NET ……………………………………………………….. 615 A. 1. Data Types ……………………………………………………………………………………. 615 A. 1. 2 Variables and Their Declaration ………………………………………………… 616 A. 1. 3 Boolean and Bitwise Operators …………………………………………………. 619 A. 1. 4 Changes Related to Procedures ………………………………………………… 620 A. 1. 5 Miscellaneous Language Changes …………………………………………….. 621 A. 2 Changes to Programming Elements ………………………………………………… 22 A. 2. 1 Constants ………………………………………………………………………………………. 622 A. 2. 2 String Functions …………………………………………………………………………… 623 11 A. 2. 3 Emptiness……………………………………………………………………………………… 623 A. 2. 4 Graphical Functionality……………………………………………………………….. 623 A. 2. 5 Mathematical Functionality………………………………………………………… 23 A. 2. 6 Diagnostics……………………………………………………………………………………. 623 A. 2. 7 Miscellaneous ……………………………………………………………………………….. 624 A. 3 Obsolete Programming Elements…………………………………………………….. 624 A. 4 Structured Exception Handling ………………………………………………………… 627 A. 5 Changes in Object-Orientation ………………………………………………………… 627 A. 5. Inheritance……………………………………………………………………………………. 628 A. 5. 2 Overloading ………………………………………………………………………………….. 628 A. 5. 3 Object Creation ……………………………………………………………………………. 628 A. 5. 4 Properties ……………………………………………………………………………………… 629 Appendix B. Language Elements by Category………………………………………………….. 631 B. Array Handling…………………………………………………………………………………….. 631 B. 2 Clipboard ……………………………………………………………………………………………… 631 B. 3 Collection Objects ………………………………………………………………………………. 632 B. 4 Common Dialogs ………………………………………………………………………………… 632 B. 5 Conditional Compilation…………………………………………………………………….. 632 B. Conversion …………………………………………………………………………………………… 633 B. 6. 1 Data Type Conversion ………………………………………………………………… 633 B. 6. 2 Other Conversion ………………………………………………………………………… 633 B. 7 Date and Time …………………………………………………………………………………….. 633 B. 8 Debugging……………………………………………………………………………………………. 634 B. Declaration…………………………………………………………………………………………… 634 B. 10 Error Handling…………………………………………………………………………………… 635 B. 11 Filesystem………………………………………………………………………………………….. 635 B. 12 Financial …………………………………………………………………………………………….. 636 B. 13 IDataObject Interface ……………………………………………………………………… 36 B. 14 Information ……………………………………………………………………………………….. 637 B. 15 Input/Output …………………………………………………………………………………….. 637 B. 16 Integrated Development Environment…………………………………………. 638 B. 17 Interaction …………………………………………………………………………………………. 638 B. 18 Mathematics………………………………………………………………………………………. 38 B. 19 Program Structure and Flow ………………………………………………………….. 639 B. 20 Programming…………………………………………………………………………………….. 640 B. 20. 1 Object Programming ………………………………………………………………… 640 B. 20. 2 Miscellaneous Programming……………………………………………………. 640 B. 21 Registry ………………………………………………………………….. …………………………. 640 B. 2 String Manipulation………………………………………………………………………….. 641 Appendix C. Operators ……………………………………………………………………………………… 643 C. 1 Arithmetic Operators …………………………………………………………………………. 643 C. 2 Assignment Operators……………………………………………………………………….. 644 C. 3 Concatenation Operators ………………………………………………………………….. 646 C. Comparison Operators ………………………………………………………………………. 646 C. 4. 1 The Is Operator……………………………………………………………………………. 647 C. 4. 2 The Like Operator ……………………………………………………………………….. 647 C. 5 Logical and Bitwise Operators………………………………………………………….. 647 12 Eqv and Imp………………………………………………………………………………………………………. 650 C. Operator Precedence………………………………………………………………………….. 650 Appendix D. Constants and Enumerations………………………………………………………… 653 D. 1 Visual Basic Intrinsic Constants……………………………………………………….. 653 D. 2 ControlChars Class……………………………………………………………………………… 656 D. 3 Visual Basic Enumerations………………………………………………………………… 656 D. 3. 1 AppWinStyle Enumeration ………………………………………………………… 656 D. 3. 2 CallType Enumeration…………………………………………………………………. 656 D. 3. 3 CompareMethod Enumeration…………………………………………………… 656 D. 3. 4 DateFormat Enumeration…………………………………………………………… 657 D. 3. 5 DateInterval Enumeration …………………………………………………………. 657 D. 3. 6 DueDate Enumeration ………………………………………………………………… 657 D. 3. FileAttribute Enumeration ………………………………………………………….. 657 D. 3. 8 FirstDayOfWeek Enumeration …………………………………………………… 657 D. 3. 9 FirstWeekOfYear Enumeration ………………………………………………….. 658 D. 3. 10 MsgBoxResult Enumeration …………………………………………………….. 658 D. 3. 11 MsgBoxStyle Enumeration ………………………………………………………. 658 D. 3. 12 OpenAccess Enumeration ………………………………………………………… 658 D. 3. 3 OpenMode Enumeration…………………………………………………………… 659 D. 3. 14 OpenModeTypes Enumeration ………………………………………………… 659 D. 3. 15 OpenShare Enumeration………………………………………………………….. 659 D. 3. 16 PrintFlags Enumeration ……………………………………………………………. 659 D. 3. 17 TriState Enumeration ……………………………………………………………….. 659 D. 3. 18 VariantType Enumeration ………………………………………………………… 659 D. 3. 9 VbStrConv Enumeration…………………………………………………………… 660 Appendix E. The VB . NET Command-Line Compiler ………………………………………… 661 E. 1 Compiler Basics …………………………………………………………………………………… 661 E. 2 Command-Line Switches……………………………………………………………………. 661 E. 2. 1 Output Filename and File Type………………………………………………….. 661 E. 2. 2 Input Files ……………………………………………………………………………………… 62 E. 2. 3 Resources………………………………………………………………………………………. 662 E. 2. 4 Code Generation…………………………………………………………………………… 663 E. 2. 5 Debugging……………………………………………………………………………………… 663 E. 2. 6 Errors and Warnings ……………………………………………………………………. 663 E. 2. 7 Language……………………………………………………………………………………….. 63 E. 2. 8 Miscellaneous………………………………………………………………………………… 664 E. 2. 9 Advanced……………………………………………………………………………………….. 664 E. 3 Using a Response File ………………………………………………………………………… 665 Appendix F. VB 6 Language Elements Not Supported by VB . NET ………………….. 667 Colophon …………………………………………………………………………………………………………… 670 3 VB . NET Language in a Nutshell Preface Why Another VB Book? Who This Book Is For How This Book Is Structured Conventions Used in This Book How to Contact Us Acknowledgments I: The Basics 1. Introduction 1. 1 Why VB . NET? 1. 2 What Is VB . NET? 1. 3 What Can You Do with VB . NET? 2. Variables and Data Types 2. 1 Variables 2. 2 Declaring Variables and Constants 2. 3 Data Types 2. 4 Arrays 2. 5 Object Variables and Their Binding 2. 6 The Collection Object 2. 7 Parameters and Arguments 3. Introduction to Object-Oriented Programming 3. 1 Why Learn Object-Oriented Techniques? 3. Principles of Object-Oriented Programming 3. 3 Classes and Objects 3. 4 Inheritance 3. 5 Interfaces, Abstract Members, and Classes 3. 6 Polymorphism and Overloading 3. 7 Scope and Accessibility in Class Modules 4. The . NET Framework: General Concepts 4. 1 Namespaces 4. 2 Common Language Runtime (CLR), Managed Code, and Managed Data 4. 3 Managed Execution 4. 4 Assemblies 4. 5 Assemblies and VB . NET 5. The . NET Fram