How do optional Parameters in Let/Get Properties work? How do optional Parameters in Let/Get Properties work? vba vba

How do optional Parameters in Let/Get Properties work?


1) Yes your code is possible.

2) This is how you pass an argument:

Assuming myObject is an object of your class:

myObject.foo(lngSubSet) = lngSuperSet 

The placement of arguments in the arglist does indeed look weird, but that's VBA for you. Say you have 4 arguments, two of which are optional, plus your right hand side. You would place them like this:

Public Property Let foo(arg1, arg2, Optional arg3, Optional arg4, _                          RHS)

and use them like this (assuming you're opting out of arg4):

myObject.foo(arg1,arg2,arg3) = RHS

3) Is there a better way to do this? There always is, depending who you ask. You could have your lngSubSet argument as a separate property entirely. That's how I tend to do it. But in your case, your way of doing things may work well for you. I don't know, it's largely a question of taste and dependent on your specific application.


This question is marked as the answer to a completely different question, "Let property of VBA class modules - is it possible to have multiple arguments? [duplicate]", so it's possible that people wanting an answer to that question might follow the link and wind up here.

That question is closed, so I'll give the answer to it here: Yes, it is possible to use multiple arguments, as described in the documentation: https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/property-let-statement

You use a ParamArray declaration.