
Sub Statement | 461
The Language
Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Usage at a Glance
• The members of a structure can be fields, properties, methods, events, or types.
Each member must be declared with an access modifier.
• You cannot assign a structure member an initial value as part of its declaration.
The initial values of structure members can be set in the structure’s constructor.
• If a structure member is an array, it cannot be explicitly dimensioned in its
definition.
• Although structures are similar to classes, they cannot explicitly inherit, nor can
they be inherited. All constructors for a structure must be parameterized, and
structures cannot define destructors.
Example
The simplest and most common use of structures is to encapsulate related variables, as
in this sample code:
Structure Person
Public Name As String
Public Address As String
Public City As String
Public State As String
Public Zip As String
Public Age As Short
End Structure
An instance of Person is declared as:
Dim personRecord As Person
As with classes, structure members use the “dot” syntax:
personRecord.Name = "Beethoven"
Version Differences
• The Structure...EndStructure construct is new to VB under .NET. It replaces the
Type...EndType construct in VB 6. The syntax and functionality differences
between the two are significant.
• VB 6 user-defined ...