1
我的問題是:爲什麼我會在vba類中使用Property Get
,Property Let
和Property Set
而不是子例程調用。舉例來說,如果我有一個類PersonCls
一個變量:爲什麼使用Property Let,Get,Set而不是子例程?
Private name as String
Private age as Integer
什麼是使用屬性語法過像這樣的優勢:
Public Sub Setname(nm as String)
name = nm
End Sub
Public Function Getname() as String
Getname = name
End Function
我環顧四周,並沒有看到這解釋得很好(見VBA: Why Use Properties Instead of Subroutines or Functions?)。提前致謝。
,因爲你可以得到/讓(套)具有相同名稱的屬性:'公設名稱( nm as String)'和'Public Get Name()as String' –