When working with optional arguments, I like to default them to Nothing
.
Sub DoSomething(ByVal Foo as String, Optional ByVal Bar as String = Nothing)
If Bar IsNot Nothing then DoSomethingElse(Bar)
DoAnotherThing(Foo)
End Sub
This works great, unless you start working with Enum
types (or an Integer
and other Data types).
In which case my Enum
list includes a 'None' value, as follows:
Enum MyEnum
None
ChoiceA
ChoiceB
End Enum
Sub DoSomething(ByVal Foo as String, Optional ByVal Bar as MyEnum= MyEnum.None)
If Bar = MyEnum.None then DoSomethingElse(Bar)
DoAnotherThing(Foo)
End Sub
It works, but I am looking for alternatives. In addition to the burden of creating a 'None' entry in a custom Enum
, this is just not possible to do with enumerations defined by the framework or a third party DLL.