User-Defined Data Types
In this section, you will learn how to create your
own data types.
|
The user-defined data types are
sometimes called structures and records. |
You use the type statement to create your own data
types. The format is as follows:
[Private | Public] Type varname
elementname [([subscripts])] As type
[elementname [([subscripts])] As type]
. . .
End Type
Notice that the name of the user-defined data type
you want to create follows the Type
keyword. If you've already declared a variable named
Student, for instance,
you can't create a user defined data type named Student.
|
You must declare all user-defined
types at the module level. It's invalid to declare
them inside procedures. You can declare a type
in a form module, but it must be declared as Private. |
Examine the following code to learn more about the
Type statement:
Type EmployeeName
First As String
Last As String
End Type
Public emp As EmployeeName
The above code declares a user defined data type
named EmployeeName. The following code initializes
and work with the variable just created.
emp.First = "Sachin"
emp.Last = "Tendulkar"
To limit the size of string variables used in the
structure, you can add the * StringLength option.
For example,
Type EmployeeName
First As String * 15
Last As String * 15
End Type
|