初学者在这里优秀课程模块。我在基础知识方面遇到了麻烦 -
当我设置(let)属性时,我得到“编译错误:错误的参数数量或无效的属性评估”与.Name
属性:
Sub test()
Dim acc As account
Set acc = New account
MsgBox (acc.Name("First Account").rowNum())
End Sub
这是“帐户”类模块:
Private strAccName As String
Private mlngRowNum As Long
Public Property Let Name(strN As String)
strAccName = strN
End Property
Public Property Get rowNum(exists As Boolean)
dim rowNum as Long
'...some logic here...
'...
getRowNum = rowNum
End Property
所以据说我在Let方法中出错了?建议非常感谢
答案 0 :(得分:0)
您可以通过等号,而不是vith括号(用于替代方法)为属性LET(对于普通数据类型)或属性SET(对象)赋值,或者读取属性GET将值赋给另一个变量,像这样:
acc.Name = "xyz"
MsgBox acc.Name
答案 1 :(得分:0)
这可能会对您有所帮助:
Sub test_class()
Dim acc As account
Set acc = New account
acc.Name = "First Account"
MsgBox acc.rowNum(1)
End Sub
class(account):
Private strAccName As String
Private mlngRowNum As Long
Public Property Let Name(strN As String)
strAccName = strN
End Property
Public Property Get rowNum(exists As Boolean)
'Dim rowNum As Long
'...some logic here...
'...
If exists Then
'getRowNum = rowNum
rowNum = 5
Else
rowNum = 10
End If
End Property