I am using vba with Excel 2007, and am writing code for a class module.
1) Is the following code even possible?...
Essentially I have two enums, call them eDATASET and eDATATSUBSET. A particular value from eDATASET should trigger an assignment from the optionally passed parameter in a Let property. Something like this:
Public Property Let foo(Optional ByVal lngSubSet as eDATASUBSET, _
ByVal lngSuperSet as eDATASET)
Select Case lngSuperSet
Case eDATASET.abc, eDATASET.def
mlngBar = lngSuperSet
Case eDATASET.xyz
'// if lngSubSet not passed, trigger error code...
mlngBar = lngSubSet
End Select
End Property
2) How do I even pass an optional parameter to a writable property when calling the object...
Aside from the seemingly backwards placement of the Optional parameters (compared with optional parameters in functions and subs), I am having trouble finding any documentation on this feature. The vba help says this:
Optional. Indicates that an argument is not required. If used, all subsequent arguments in arglist must also be optional and declared using the Optional keyword. Note that it is not possible for the right side of a Property Let expression to be Optional.
and the following from vbusers.com. Neither explain much in the way of usage. So how would i pass the optional parameter when calling the object from a code module... oObj.foo = ???
3) Is there a better way to do this?...
I have a basic understanding of oop (at least in how it is implemented in vba). Is there a better way to conditionally accept a parameter into an object?
