Type usertype elementname As typename
[ elementname As typename]
. . .
End Type
Defines a user-defined data type containing one or more elements.
The Type statement has these parts:
Part Description |
|
Type Marks the beginning of a user-defined type. |
|
usertype Name of a user-defined data type. It follows standard variable naming conventions. |
|
elementname Name of an element of the user-defined data type. It follows standard variable-naming conventions. |
|
subscripts Dimensions of an array element. You can declare multiple dimensions. |
|
typename One of these data types: Integer, Long, Single, Double, String (for variable-length strings), String * length (for fixed-length strings), Variant, or another user-defined type. The argument typename can't be an object type. End Type Marks the end of a user-defined type. |
Once you have declared a user-defined type using the Type statement, you can declare a variable of that type anywhere in your script. Use Dim or Static to declare a variable of a user-defined type. Line numbers and line labels aren't allowed in Type...End Type blocks.
User-defined types are often used with data records because data records frequently consist of a number of related elements of different data types. Arrays cannot be an element of a user defined type in Enable.
Example:
' This sample shows some of the features of user defined types
Type type1
a As Integer
d As Double
s As String
End Type
Type type2
a As String
o As type1
End Type
Type type3
b As Integer
c As type2
End Type
Dim type2a As type2
Dim type2b As type2
Dim type1a As type1
Dim type3a as type3
Sub Form_Click ()
a = 5
type1a.a = 7472
type1a.d = 23.1415
type1a.s = "YES"
type2a.a = "43 - forty three"
type2a.o.s = "Yaba Daba Doo"
type3a.c.o.s = "COS"
type2b.a = "943 - nine hundred and forty three"
type2b.o.s = "Yogi"
MsgBox type1a.a
MsgBox type1a.d
MsgBox type1a.s
MsgBox type2a.a
MsgBox type2a.o.s
MsgBox type2b.a
MsgBox type2b.o.s
MsgBox type3a.c.o.s
MsgBox a
End Sub