开发者

Is there a way to test if a Function/Sub is available in VB6?

开发者 https://www.devze.com 2023-01-02 23:58 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号