類別可以包含特性與方法。
Property Let 允許一般使用者將值指派給專用類別變數。
Property Get 為唯讀特性,用於擷取專用類別變數。
方法允許類別執行使用者想要的作業。方法就是函式或子常式。
範例:
在下方範例中,我們使用特性和方法來包裝專用變數。
Class Comp
Private modStrType
Public Property Let ComputerType(strType)
modStrType = strType
End Property
Public Property Get ComputerType
ComputerType = modStrType
End Property
Public Function Funct1
'Add business logic using class variables
End Function
Public Sub Sub1
'Add business logic using class variables
End Sub
End Class
Set objComp = new Comp
objComp.ComputerType = "Mac" 'Let Property
str1 = objComp.ComputerType 'Get Property. Here, the value of str1 is Mac
objComp.Funct1
objComp.Sub1