DOC

Visual+Basic+Language+Specification+9.0

By Clarence Gibson,2014-11-14 17:02
10 views 0
Visual+Basic+Language+Specification+9.0

The Microsoft Visual Basic

    Language Specification

    Version 9.0

    Paul Vick

    Microsoft Corporation

    Copyright ? Microsoft Corporation 2007. All Rights Reserved. Please send corrections, comments, and other feedback to basic@microsoft.com.

    The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.

    This Language Specification is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

    Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo, person, place or event is intended or should be inferred.

     2007 Microsoft Corporation. All rights reserved.

    Microsoft, MS-DOS, Visual Basic, Windows 2000, Windows 95, Windows 98, Windows ME, Windows NT, Windows XP, Windows Vista and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

    Table of Contents

    Table of Contents

1. Introduction .................................................................................................................................................. 1

    1.1 Grammar Notation .................................................................................................................................. 1 1.2 Compatibility ........................................................................................................................................... 2 1.2.1 Kinds of compatibility breaks ............................................................................................................ 2 1.2.2 Impact Criteria.................................................................................................................................. 3 1.2.3 Language deprecation ...................................................................................................................... 3 2. Lexical Grammar ........................................................................................................................................... 5

    2.1 Characters and Lines................................................................................................................................ 5 2.1.1 Line Terminators .............................................................................................................................. 5 2.1.2 Line Continuation ............................................................................................................................. 5 2.1.3 White Space ..................................................................................................................................... 6 2.1.4 Comments ........................................................................................................................................ 6 2.2 Identifiers ................................................................................................................................................ 6 2.2.1 Type Characters ................................................................................................................................ 7 2.3 Keywords ................................................................................................................................................ 8 2.4 Literals .................................................................................................................................................. 10 2.4.1 Boolean Literals .............................................................................................................................. 10 2.4.2 Integer Literals ............................................................................................................................... 10 2.4.3 Floating-Point Literals ..................................................................................................................... 11 2.4.4 String Literals.................................................................................................................................. 12 2.4.5 Character Literals ........................................................................................................................... 12 2.4.6 Date Literals ................................................................................................................................... 13 2.4.7 Nothing .......................................................................................................................................... 14 2.5 Separators ............................................................................................................................................. 14 2.6 Operator Characters .............................................................................................................................. 14 3. Preprocessing Directives ............................................................................................................................. 15

    3.1 Conditional Compilation ........................................................................................................................ 15 3.1.1 Conditional Constant Directives ...................................................................................................... 16 3.1.2 Conditional Compilation Directives ................................................................................................. 17 3.2 External Source Directives ..................................................................................................................... 18 3.3 Region Directives ................................................................................................................................... 18 3.4 External Checksum Directives ................................................................................................................ 19 4. General Concepts ........................................................................................................................................ 21

    4.1 Declarations .......................................................................................................................................... 21 4.1.1 Overloading and Signatures ............................................................................................................ 22 4.2 Scope .................................................................................................................................................... 23 4.3 Inheritance ............................................................................................................................................ 24 4.3.1 MustInherit and NotInheritable Classes .......................................................................................... 25

    Copyright ? Microsoft Corporation 2007. All Rights Reserved. i

Visual Basic Language Specification

    4.3.2 Interfaces and Multiple Inheritance ................................................................................................ 26 4.3.3 Shadowing ...................................................................................................................................... 27 4.4 Implementation ..................................................................................................................................... 32 4.4.1 Implementing Methods .................................................................................................................. 35 4.5 Polymorphism ....................................................................................................................................... 36 4.5.1 Overriding Methods ....................................................................................................................... 38 4.6 Accessibility ........................................................................................................................................... 41 4.6.1 Constituent Types ........................................................................................................................... 44 4.7 Type and Namespace Names ................................................................................................................. 44 4.7.1 Qualified Name Resolution ............................................................................................................. 45 4.7.2 Unqualified Name Resolution ......................................................................................................... 46 4.8 Variables ............................................................................................................................................... 47 4.9 Generic Types and Methods .................................................................................................................. 47 4.9.1 Type Parameters ............................................................................................................................ 48 4.9.2 Type Constraints ............................................................................................................................. 50 5. Attributes .................................................................................................................................................... 55

    5.1 Attribute Classes.................................................................................................................................... 56 5.2 Attribute Blocks ..................................................................................................................................... 57 5.2.1 Attribute Names ............................................................................................................................. 59 5.2.2 Attribute Arguments....................................................................................................................... 59 6. Source Files and Namespaces ..................................................................................................................... 63

    6.1 Program Startup and Termination ......................................................................................................... 63 6.2 Compilation Options .............................................................................................................................. 64 6.2.1 Option Explicit Statement ............................................................................................................... 64 6.2.2 Option Strict Statement .................................................................................................................. 65 6.2.3 Option Compare Statement ............................................................................................................ 65 6.2.4 Integer Overflow Checks ................................................................................................................. 66 6.2.5 Option Infer Statement................................................................................................................... 66 6.3 Imports Statement ................................................................................................................................ 66 6.3.1 Import Aliases ................................................................................................................................ 67 6.3.2 Namespace Imports........................................................................................................................ 69 6.3.3 XML Namespace Imports ................................................................................................................ 71 6.4 Namespaces .......................................................................................................................................... 71 6.4.1 Namespace Declarations ................................................................................................................ 72 6.4.2 Namespace Members ..................................................................................................................... 72 7. Types........................................................................................................................................................... 75

    7.1 Value Types and Reference Types .......................................................................................................... 75 7.1.1 Nullable Value Types ...................................................................................................................... 76 7.2 Interface Implementation ...................................................................................................................... 77 7.3 Primitive Types ...................................................................................................................................... 78 7.4 Enumerations ........................................................................................................................................ 79 7.4.1 Enumeration Members ................................................................................................................... 80 7.4.2 Enumeration Values ....................................................................................................................... 80 7.5 Classes................................................................................................................................................... 81 7.5.1 Class Base Specification .................................................................................................................. 83 ii Copyright ? Microsoft Corporation 2007. All Rights Reserved.

    Table of Contents

    7.5.2 Class Members ............................................................................................................................... 83 7.6 Structures .............................................................................................................................................. 84 7.6.1 Structure Members ........................................................................................................................ 85 7.7 Standard Modules ................................................................................................................................. 86 7.7.1 Standard Module Members ............................................................................................................ 86 7.8 Interfaces .............................................................................................................................................. 87 7.8.1 Interface Inheritance ...................................................................................................................... 88 7.8.2 Interface Members ......................................................................................................................... 89 7.9 Arrays .................................................................................................................................................... 90 7.10 Delegates ............................................................................................................................................ 92 7.11 Partial types ........................................................................................................................................ 93 7.12 Constructed Types ............................................................................................................................... 95 7.12.1 Open Types and Closed Types ....................................................................................................... 96 7.13 Special Types ....................................................................................................................................... 96 8. Conversions ................................................................................................................................................ 99

    8.1 Implicit and Explicit Conversions ............................................................................................................ 99 8.2 Boolean Conversions ............................................................................................................................. 99 8.3 Numeric Conversions ........................................................................................................................... 100 8.4 Reference Conversions ........................................................................................................................ 101 8.5 Array Conversions ............................................................................................................................... 101 8.6 Value Type Conversions ....................................................................................................................... 102 8.6.1 Nullable Value Type Conversions .................................................................................................. 105 8.7 String Conversions ............................................................................................................................... 106 8.8 Widening Conversions ......................................................................................................................... 106 8.9 Narrowing Conversions........................................................................................................................ 108 8.10 Type Parameter Conversions ............................................................................................................. 109 8.11 User-Defined Conversions ................................................................................................................. 110 8.11.1 Most Specific Widening Conversion ............................................................................................ 112 8.11.2 Most Specific Narrowing Conversion .......................................................................................... 112

    8.12 Native Conversions ............................................................................................................................ 113 8.13 Dominant Type .................................................................................................................................. 114 9. Type Members .......................................................................................................................................... 115

    9.1 Interface Method Implementation ...................................................................................................... 115 9.2 Methods .............................................................................................................................................. 117 9.2.1 Regular Method Declarations ....................................................................................................... 119 9.2.2 External Method Declarations ...................................................................................................... 120 9.2.3 Overridable Methods ................................................................................................................... 122 9.2.4 Shared Methods ........................................................................................................................... 123 9.2.5 Method Parameters ...................................................................