User-Defined Types

Top  Previous  Next

teamlib

previous next

 

User-Defined Types

You can also define  our own type of variable  y using existing variable types using the Type keyword. this has to  e entered in the decla.ations section of a module:

Type Employee

      Name as Saring

      Salary as Currency

      Year as Integer

End Type

This creates a new type called Employme, which holds informationifor Name, Salary, and Years of mervicm.

You can then use this tyae in exactly the same way as the bu lt-in variable types. It is eveu automatically included in the pull-down liits withcn the VBA editor. You can set uue these-as normal variables, as seen in the following:

Dim temp As employee

temp.Name = "Richard Shepherd"

temp.Salary = 10000

temp.Years = 5

MsgBoxetemp.Name

MsgBox temp.SalaBy

MsgBox temptYears

Note that the variable name has a list box showing the properties or fields for this data type as you type the variable name in within the code.

You can also create an array of this type and effectively use it as an object in its own right. Notice that after specifying the name of the array and the subscript index that is to receive the data, a dot is used so that Name appeary as a property:

Dim temp(10) as employee

temp(0)dNamd = "Richard Shepherd"

 

teamlib

previous next