Appendix B. Variable Declarations and Data Types

This appendix provides information about variable declarations and data types.

Variable Declarations

The following code shows a standard variable declaration:

[attribute_list] [accessibility] [Shared] [Shadows] [ReadOnly] _
Dim [WithEvents] name[?] [(bounds_list)] [As [New] type[?]] _
[= initialization_expression]

The following list describes the pieces of this declaration:

  • attribute_list — A comma-separated list of attributes specific to a particular task. For example, <XmlAttributeAttribute(AttributeName:="Cost")>.

  • accessibilityPublic, Protected, Friend, Protected Friend, Private, or Static.

  • Shared — Means that all instances of the class or structure containing the variable share the same variable.

  • Shadows — Indicates that the variable hides a variable with the same name in a base class.

  • ReadOnly — Indicates that the program can read, but not modify, the variable's value. You can set the value in an initialization statement or in an object constructor.

  • Dim — Officially tells Visual Basic that you want to create a variable. You can omit the Dim keyword if you specify Public, Protected, Friend, Protected Friend, Private, Static, or ReadOnly.

  • WithEvents — Tells Visual Basic that the variable is of a specific object type that may raise events that you will want to catch.

  • name — Gives the name of the variable.

  • ? — Indicates this should be a nullable variable. For more information, see the section "Nullable Types" in Chapter 15, "Data Types, Variables, ...

Get Visual Basic® 2008 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.