Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Name of Class instance
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Name of Class instance
John,
I'm thinking you'd create a corresponding let property and assign it. hth, Doug "Balmain Bushwalker" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Name of Class instance
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) "Balmain Bushwalker" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Get Property value of class instance by passing string property name | Excel Programming | |||
Scripting Dictionary in a class instance | Excel Programming | |||
Ensure single class instance but with multiple references to it | Excel Programming | |||
Userform level class instance doesn't recognize methods | Excel Programming | |||
Class Instance Identifier | Excel Programming |