<< Click to Display Table of Contents >> Type (statement) |
Type TypeName
Element As Type
Element As Type
Element As Type
.
.
.
End Type
Declares a user-defined type.
TypeName is the name of the new type.
Element is the name of an element of this type.
Type is the data type of this element (Integer, Long, Single, Double, String, String*n, Variant or a user-defined type).
After you have defined a user-defined type, you can declare variables of this new type using the commands Dim x As TypeName and Static x As TypeName.
To access an element, use dot notation: Variable.Element.
The Type statement may not be used inside Sub or Function statements.
See also: Dim, Static, With, section Data types
Example:
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 var2a As type2
Dim var2b As type2
Dim var1a As type1
Dim var3a as type3
Sub Test
a = 5
var1a.a = 7472
var1a.d = 23.1415
var1a.s = "TEST"
var2a.a = "43 - forty-three"
var2a.o.s = "Hi"
var3a.c.o.s = "COS"
var2b.a = "943 - nine hundred forty-three"
var2b.o.s = "Yogi"
MsgBox var1a.a
MsgBox var1a.d
MsgBox var1a.s
MsgBox var2a.a
MsgBox var2a.o.s
MsgBox var2b.a
MsgBox var2b.o.s
MsgBox var3a.c.o.s
MsgBox a
End Sub