Try this:
Private pSkipTrade As Boolean
Public Property Let SkipTrade(lSkipTrade As Boolean)
pSkipTrade = lSkipTrade
End Property
Property Get SkipTrade() As Boolean
SkipTrade = pSkipTrade
End Property
Somewhere else in your code you are using another variable (e.g., value
) to set this property. If this variable is not of Type Boolean
(e.g., a Long
, Double
, or Decimal
), then you can do something like:
Sub Test()
Dim MyObject As Object
Dim Value As Double '## or, whatever
'# CREATE THE CLASS OBJECT
Set MyObject = New cMyObject '## Modify to be your correct Type
Value = Application.InputBox("Enter any number")
'# ASSIGN THE PROPERTY VALUE BASED ON A LOCAL VARIABLE/LOGIC
' use boolean logic to test whether "value = 0"
' a non-zero value will return "True"
MyObject.SkipTrade = Not (CDbl(Value) = 0)
'# Display the value, so you can see that this is working correctly:
MsgBox "The value of SkipTrade is: " & MyObject.SkipTrade
End Sub
If you have multiple conditions, it would be better to use a Function
call to return the property value, during the object's property assignment.
You can call a function like:
MyObject.SkipTrade = CheckSkipTrade(value)
With a function in your main code module like this, which could be modified to include any logic that you might need to incorporate:
Function CheckSkipTrade(value) As Boolean
Dim myVal as Boolean
If IsNumeric(value) Then
'returns true or false test whether 'value' = 0.
myVal = Not(CDbl(value) = 0)
Else:
myVal = False
End If
'# Return the value of the function test:
CheckSkipTrade = myVal
End Function
Notice that in the above example it is very explicit -- not hidden -- that you are directly making an assignment to the SkipTrade
property of MyObject
class 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.