Name of Class instance

B

Balmain Bushwalker

When executing code within a Class Module I want to access the Name of the
instance of the class. Anyone know how?

In the example below, I am executing code in the class module dRange and
wish to know within the calss module that the instance that called it was
tData rather than rData. How do I access the name tData?


Sub Test
Dim tData As New dRange, rData As New dRange, X
X = tData.Info
End Sub

Code below is within the dRange class module:

Public Property Get Info()
Info= <Code required to return the information that "tData" is the
object name>
End Property

Thanx:
John
 
D

Doug Glancy

John,

I'm thinking you'd create a corresponding let property and assign it.

hth,

Doug
 
C

Chip Pearson

I'm not exactly what you're looking for. If you have a class named Class1
and in a standard code module you have

Sub AAA()
Dim C As Class1
Set C = New Class1
End Sub

and you want to get the string "C", then I don't think you can do that. If,
in Class1, you want to refer to property or method of that instance of the
class, you can use the "Me" keyword. "Me" always refers to the instance of
the class that in which it resides. So, in Class1, you could use Me.Name to
return the value of the Name property of that instance of Class1. This
assumes that you have written a Property Get/Let named "Name". There is no
intrinsic name of an instance of a class.

If you want to return the name of the class (but not the instance of the
class), you can use the following in Class1:

Function MyType() As String
MyType = TypeName(Me)
End Function

This will return the string "Class1".

If all you need is a unique identifier string of the instance of the class,
you can use

Public Function ThisObj() As String
ThisObj = CStr(ObjPtr(Me))
End Function

You might provide a few more details about exactly what you are looking for.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top