|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
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 2005 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:
EmpNumber As Integer ' Defaults to Public access.
EmpOfficePhone As String
EmpHomePhone As String ' Cannot be declared Private inside Type.
Visual Basic 2005
In Visual Basic 2005, 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 2005 unifies the syntax for structures and classes. Structures support most of the features of classes, including methods.