Is there a way to test if a Function/Sub is available in VB6?
We have a few Subs (like a WriteErrorToLog
and some AutomatedTesting
) that I'd like to make optiona开发者_运维知识库l 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
.
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
精彩评论