如标题所示,这两个都是声明变量,但是我在一个程序中看到这样一段代码:
Public Property Get Locked(RowIndex As Integer, ColIndex As Integer) As Boolean
Locked = a_RowColLock(ColIndex, RowIndex)
End PropertyPublic Property Let Locked(RowIndex As Integer, ColIndex As Integer, blnLock As Boolean)
With m_MsFlexGrid_Pack
a_RowColLock(ColIndex, RowIndex) = blnLock
End With
End Property谁能给我解释一下这两个函数的区别?
这两个函数名字一样,在什么情况下用的是get定义的这个 Locked函数,什么情况下用的是另一个?
Public Property Get Locked(RowIndex As Integer, ColIndex As Integer) As Boolean
Locked = a_RowColLock(ColIndex, RowIndex)
End PropertyPublic Property Let Locked(RowIndex As Integer, ColIndex As Integer, blnLock As Boolean)
With m_MsFlexGrid_Pack
a_RowColLock(ColIndex, RowIndex) = blnLock
End With
End Property谁能给我解释一下这两个函数的区别?
这两个函数名字一样,在什么情况下用的是get定义的这个 Locked函数,什么情况下用的是另一个?
Dim b As Boolean
Set c = New Class1
'下面这个属性赋值调用 Property Let,如果类中没有 Property Let,下面语句出错,即属性是只读的。
c.Locked(1,1) = True
'下面这个属性取值调用 Property Get,如果类中没有 Property Get,下面语句出错,即属性是不可读取的。
b = c.Locked(1,1)
如果如果属性类型是对象,则 Property Let 换成 Property Set。