请原谅代码中的任何愚蠢错误,因为这是我第一次尝试使用类,而且我在网上找不到任何真正将其放入其中的教程,really对于像我这样的傻瓜来说,简单的术语。我尽力遵循 MS 指南:https://msdn.microsoft.com/en-us/library/aa716315(v=vs.60).aspx https://msdn.microsoft.com/en-us/library/aa716315(v=vs.60).aspx,但我真的不明白我在做什么,这使得很难解释我应该改变什么。
我正在尝试创建一个存储三个数据、两个整数和一个字符串的类。我把它放在一个名为的类模块中tdata
:
Sub tdata()
Dim tnumber As Integer, tacct As Integer
Dim ttype As String
Public Property Get t_acct() As Integer 'don't forget the account number!
t_acct = tacct
End Property
Public Property Let t_acct(ByVal newval As Integer)
t_acct = newval
End Property
Public Property Get t_numb() As Integer 'T1, T2, or T3 as applicable
t_numb = tnumb
End Property
Public Property Let t_numb(ByVal newval As Integer)
t_numb = newval
End Property
Public Property Get t_type() As String 'PF or MW
t_type = ttype
End Property
Public Property Let t_type(ByVal newstr As String)
t_type = newstr
End Property
End Sub
然后我在我的函数中调用它
Set t_info = New tdata
t_info.t_acct = wb2.Sheets(1).Cells(d, 1) 'd is just a row counter in a for loop
t_info.t_numb = Right(wb2.Sheets(1).Cells(d, 4), 1)
t_info.t_type = wb2.Sheets(1).Cells(d, 6)
references(CStr(wb2.Sheets(1).Cells(d, 5))).Add t_info
(当然,这不是全部代码,而只是调用它的部分)
我有Option Explicit
所有这些有趣的东西都在,一切都编译得很好,但是当它到达函数片段的第二行时,它会尝试 maket_info.t_acct
等于某物,它会走向Let
为该功能发挥作用,并永远留在那里。具体来说,它在
Public Property Let t_acct(ByVal newval As Integer)
t_acct = newval
永远。为什么是这样?我如何让它设置(错误,让)t_acct等于我想要的东西?