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] 

In this code, the following is true:

  • 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.

  • bounds_list - Bounds for an array.

  • New - Use New to make a new instance of an object variable. Include parameters for the class’s constructor if appropriate.

  • type - The variable’s data type.

  • initialization_expression - An expression that sets the initial value for the variable.

Visual Basic enables you to declare and initialize more than one variable in a single declaration statement, but that can make the code more difficult to read. To avoid possible later confusion, declare only variables of one type in a single statement.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net