O'Reilly logo

Visual Basic® 2010 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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")>.

  • accessibility — Public, 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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required