Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Property value of class instance by passing string property name [email protected] Excel Programming 2 October 19th 07 05:47 PM
Scripting Dictionary in a class instance Art Excel Programming 3 March 28th 07 01:20 PM
Ensure single class instance but with multiple references to it [email protected] Excel Programming 4 January 6th 06 02:31 AM
Userform level class instance doesn't recognize methods =Ray= Excel Programming 2 December 16th 05 05:58 PM
Class Instance Identifier Chip Pearson Excel Programming 6 June 29th 04 09:34 AM


All times are GMT +1. The time now is 11:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"