我已經有一段時間沒有用 VBA 編程了。我想清理我的代碼,讓它對未來的我更具可讀性。所以我開始做一些課程。這是我的簡化問題:
'class code ' class is called cls_curriculum_object
Dim m_curriculum_object_name As String
Public Property Get curriculum_object_name()
curriculum_object_name = m_curriculum_object_name
End Property
Public Property Set curriculum_object_name(curriculum_object_name)
m_curriculum_object_name = curriculum_object_name
End Property
' button code
Dim cls_curriculum_object As cls_curriculum_object
Set cls_curriculum_object = New cls_curriculum_object
ActiveSheet.Cells(ActiveCell.Row, 4).Select
Set cls_curriculum_object.curriculum_object_name = Trim(ActiveCell.FormulaR1C1)
' if I run it. It works fine but if I change the code to
Set cls_curriculum_object.curriculum_object_name = "foo"
' I get a VBA compile error message
先感謝您。
uj5u.com熱心網友回復:
你有一個String需要Property Let,而不是Property Set:
Public Property Let curriculum_object_name(curriculum_object_name)
m_curriculum_object_name = curriculum_object_name
End Property
...
cls_curriculum_object.curriculum_object_name = Trim(ActiveCell.FormulaR1C1)
cls_curriculum_object.curriculum_object_name = "foo"
旁注,但snake_case非常不可讀。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/485424.html
