Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overload functions from the VBA standard library like IsEmpty()?

Tags:

excel

vba

I want to make a local version of IsEmpty() in a class like this:

Public Dict As Dictionary

Public Function isEmpty(columnName As Variant) As Boolean
isEmpty = IsEmpty(Dict(columnName))
End Function

This is for information hiding, so that I can call

classInstance.isEmpty("someField")

instead of

isEmpty(classInstance.Dict("someField"))

and therefore not expose the class' internal data structure.

But the problem is that the version of isEmpty() that I've declared seems to be overriding any reference to the VBA library version of IsEmpty(), because it's generating an Out of stack error and crashing Excel. I assume this is because the isEmpty = IsEmpty(...) call is causing infinite recursion.

Is there a way that I can explicitly reference the standard version of IsEmpty() that I would like to call here?

like image 309
sigil Avatar asked Feb 11 '23 18:02

sigil


1 Answers

Yes. Explicitly reference the standard library.

VBA.IsEmpty()

Bonus:
IsEmpty actually belongs to the Information object. A fully explicit call looks like this.

bool = VBA.Information.IsEmpty(var)

object browser

like image 198
RubberDuck Avatar answered May 22 '23 15:05

RubberDuck