tags:

views:

41

answers:

1

We have a few Subs (like a WriteErrorToLog and some AutomatedTesting) that I'd like to make optional in case we want to reuse a component.

I'd like to be able to do something like if AddressOf( Sub) is valid then execute Sub.

+3  A: 

The structured way of doing this is to make the sub/function part of an interface. You can now let two distinct classes implement that interface, one providing empty implementations and the other one providing the real logic.

Now you can simply assign whatever class you need and call the method. If you assigned the empty implementation class, no code will be executed.

Dim obj As IMyInterface
Set obj = New EmptyImplementationClass

Call obj.SomeSub() ''// Executes no code

Set obj = New RealImplementationClass

Call obj.SomeSub() ''// Executes the real implementation
Konrad Rudolph
That's one of those things that's sooo simple but has huge ramifications for how you wrote code.
Clay Nichols