What Object.Class am I in?

Applies To

OS:
VB:
NT, 9x, 2000
5, 6

Sometimes your code needs to know what class and object it is in (for instance, if you have a generalized error handling routine). Yes, you can have a variable that holds the name of the class string. But that is not cool and more importantly it is time-consuming and error-prone. If you have a lot of classes, it can take the fun out of programming.

VB provides a really cool function that returns the name of class you are in. It is called TypeName.

Dim ClassName As String
ClassName = TypeName(Me)


You can also find out the name of the full class string (Object.Class) using the code below, however, you must keep the name of the Project identical as the name of the Application Title (go to Project Properties, then to the Make tab, see the Application Title). It is very easy and it should be a norm for ActiveX DLLs.

Dim ClassString As String
ClassString = App.Title & "." & TypeName(Me)