Type Statement

Named Arguments

No

Syntax

[Private | Public] Type varname
						elementname [([subscripts])] As type
   [elementname [([subscripts])] As type]
   . . .
End Type

Public

Use: Optional

Type: Keyword

Gives the user-defined type scope through all procedures in all modules in the project. Public and Private are mutually exclusive.

Private

Use: Optional

Type: Keyword

Restricts the scope of the user-defined type to those procedures within the same module. Public and Private are mutually exclusive.

varname

Use: Required

The name of the user-defined type.

elementname

Use: Required

Data Type: Any

The name of an element of the user-defined type.

subscripts

Use: Optional

Data Type: Numeric literal or constant

The dimensions of an array element.

type

Use: Required

The data type of the element.

Description

Used at module level to define a user-defined type.

Rules at a Glance

  • A user-defined type can contain one or more elements.

  • The Type statement can't be used within a procedure; it can be used only within the declaration section of a module.

  • In form and code modules, user-defined types are Public by default. You can reduce the scope and visibility of a user-defined type to the current module by using the Private keyword.

  • Until Version 6 of VB, publicly declared user-defined types were not permitted in class modules. Now, VB6 has introduced the remote user-defined types, which allow you to declare a property as a user-defined type, or have a class method return a user-defined type. The ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.