2014-04-02 30 views
0

問:爲什麼我從這段代碼中除了0以外什麼都沒有? (通過MsgBox)第一次嘗試面向對象的VBA失敗

上下文:新手試圖學習在Excel VBA中使用我自己的類。

1類是一類模塊,這裏有代碼:

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()是在模塊1子,你在這裏看到的

Dim Home As Class1 

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

代碼執行,但Home.Phone只報告爲0(我猜初始值)我做錯了什麼?

回答

0

變化pPhone = PhonepPhone = Value

應該

Public Property Let Phone(Value As Integer) 
pPhone = Value 
End Property 
相關問題