Structure Declaration for Visual Basic 6.0 Users

Visual Basic considers structures and user-defined types (UDTs) to be the same type of programming element. Visual Basic 2008 updates structure declaration for unification and improved readability.

Visual Basic 6.0

In Visual Basic 6.0, you declare a structure using the Type ... End Type construction. The structure and its members all default to public access. Explicit access declaration is optional. The following example shows a valid structure declaration:

Type Employee

EmpNumber As Integer ' Defaults to Public access.

EmpOfficePhone As String

EmpHomePhone As String ' Cannot be declared Private inside Type.

End Type

Visual Basic 2005

In Visual Basic 2008, the Type statement is not supported. You must declare structures using the Structure statement as part of a Structure ... End Structure construction. Every member of a structure must have an access modifier, which can be Public, Friend, or Private. You can also use the Dim statement, which defaults to public access. The structure in the preceding example can be declared as follows:

Structure Employee
  Public EmpNumber AsInteger    'Must declare access, even if Public. 
  Dim EmpOfficePhone AsString   'Still defaults to Public access. 
  Private EmpHomePhone AsString 'Can be made Private inside Structure. 
EndStructure

Visual Basic 2008 unifies the syntax for structures and classes. Structures support most of the features of classes, including methods.

See Also

Concepts

Programming Element Support Changes Summary

Reference

Structure Statement

Dim Statement (Visual Basic)

Public (Visual Basic)

Private (Visual Basic)