MACRO LIBRARY

User-Defined Types example

Free public access. No account or subscription required.

Files

User-defined types example

Code

'This demonstrates how to create user-defined data types with the Type statement
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'For more info: http://www.cpearson.com/excel/classes.aspx
'Using types - inferior to classes because you can't do much to control values; _
    for example you cannot control whether a negative number is entered for salary. _
    A class is necessary.
    
Type Employee
    Name As String
    Address As String
    Salary As Double
End Type
    
Dim president As Employee
    
Sub main()
president.Name = "Keith"
president.Salary = 100000
president.Address = "12119 South Pine Dr Apt 328"
    
Debug.Print president.Name
End Sub