This is a discussion on Passing args in a class within the Excel Questions forums, part of the Question Forums category; Omitting it would be the same as adding ByRef. ByVal would have been clearer....
Sorry I seemed to misunderstand your question.
It makes sense to me that Property Set/Let would be a one-way (in only) deal, as we're trying to save it for later use. I am not understanding the difference if the property is in a class or standard module however?
I only tested this...
Standard Module (Module1)
Class Module (Class1)Code:Option ExplicitSub example() Dim lCnt As Long Dim cls1 As Class1 Set cls1 = New Class1 lCnt = 3 cls1.Count = lCnt MsgBox "Class property returns " & cls1.Count & vbLf & "lCnt (passed byRef) returns " & lCnt Module2.MyProperty = lCnt MsgBox "Std Mod Property returns " & Module2.MyProperty & vbLf & "lCnt (passed byVal) returns " & lCnt Module2.MyOtherProperty = lCnt MsgBox "Std Mod Property returns " & Module2.MyOtherProperty & vbLf & "lCnt (passed byRef) STILL returns " & lCnt End Sub
Standard Module w/Properties (Module2)Code:Option Explicit Private lCount As Long Public Property Get Count() As Long Count = lCount End Property Public Property Let Count(ByRef lNewValue As Long) lNewValue = lNewValue + 1 lCount = lNewValue End Property
...what am I missing?Code:Option Explicit Private lMyProperty As Long Private lOtherProperty As Long Public Property Get MyProperty() As Long MyProperty = lMyProperty End Property Public Property Let MyProperty(ByVal lNewValue As Long) lNewValue = lNewValue + 1 lMyProperty = lNewValue End Property Public Property Get MyOtherProperty() As Long MyOtherProperty = lOtherProperty End Property Public Property Let MyOtherProperty(ByRef lSomeInt As Long) lSomeInt = lSomeInt + 1 lOtherProperty = lSomeInt End Property
Properties behave the same in a module as a class module, or is that your point?
Last edited by Kyle123; Apr 21st, 2017 at 12:24 PM.
Yes or specifically, if there is any difference in how the argument is passed to a property Let/Set in a Standard vs Class module.