首次尝试面向对象的VBA失败

时间:2014-04-02 05:47:25

标签: excel-vba vba excel

问题:为什么我的代码中只有0? (通过MsgBox)

上下文:新手试图学习在Excel VBA中使用我自己的类。

Class1是一个类Module,其代码如下:

 Private pPhone As Integer

 Public Property Get Phone() As Integer
 Phone = pPhone
 End Property

 Public Property Let Phone(Value As Integer)
 pPhone = Phone
 End Property

如你所见,Test()是Module1中的一个子

Dim Home As Class1

Public Sub Test()
Set Home = New Class1
Home.Phone = 3
MsgBox Home.Phone
End Sub

代码执行,但Home.Phone仅报告为0(我猜初始值)我做错了什么?

1 个答案:

答案 0 :(得分:0)

pPhone = Phone更改为pPhone = Value

应该是

 Public Property Let Phone(Value As Integer)
 pPhone = Value
 End Property
相关问题