This documentation is archived and is not being maintained.

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.

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

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 As Integer    'Must declare access, even if Public. 
  Dim EmpOfficePhone As String   'Still defaults to Public access. 
  Private EmpHomePhone As String 'Can be made Private inside Structure. 
End Structure


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

Show: