Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb6

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.

like image 724
Clay Nichols Avatar asked Nov 20 '25 18:11

Clay Nichols


1 Answers

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
like image 122
Konrad Rudolph Avatar answered Nov 23 '25 06:11

Konrad Rudolph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!