It must be something obvious but I'm stuck so maybe you guys can help me.
Consider the following code inside a VBA custom object:
Private pSkipTrade As Boolean
Property Let SkipTrade(value As Double):
If value = 0 Then
pSkipTrade = False
Else
pSkipTrade = True
End If
End Property
Public Property Get SkipTrade() As Boolean
SkipTrade = pSkipTrade
End Property
Can anyone help me?
tks in advance!
Try this:
Somewhere else in your code you are using another variable (e.g.,
value) to set this property. If this variable is not of TypeBoolean(e.g., aLong,Double, orDecimal), then you can do something like:If you have multiple conditions, it would be better to use a
Functioncall to return the property value, during the object's property assignment.You can call a function like:
With a function in your main code module like this, which could be modified to include any logic that you might need to incorporate:
Notice that in the above example it is very explicit -- not hidden -- that you are directly making an assignment to the
SkipTradeproperty ofMyObjectclass object? On the contrary, your method essentially calls a subroutine hidden away in the object module, that assigns a value to the property. Does it work? Yes. Is it the best way to do it? I don't think so; it a very confusing way of coding which will make later troubleshooting (especially if you hand this project off to someone else) that much more difficult.Coding explicitly is better than coding implicitly.