473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Getting Name of Class Instance (VB 6 & VB 2005)

Is there a way in VB 6 (and VB 2005) to get the instance name from a class.
For example

class MyClass
'some methods and properties
public property get VarName() as string
VarName = somefunction(me)
end property

end class
dim myVar as MyClass
Set myVar = new MyClass
debug.print myVar.VarName

The output would be "myVar"

The TypeName() function returns the name of the class itself, in this case
"MyClass". What I'm looking for is a class internal method that will return
the name of the instance variable.

Thanks,
Mike Ober.


Nov 21 '05 #1
5 2422
Michael D. Ober wrote:
Is there a way in VB 6 (and VB 2005) to get the instance name from a
class.


No, the closest you can come is ObjPtr(Me). The concept of instance name is kind of
odd, if you think about it. Consider that a single instance reference may be held in
multiple variables and/or collections.
--
Working Without a .NET?
http://classicvb.org/petition
Nov 21 '05 #2
> Is there a way in VB 6 (and VB 2005) to get the instance name from a
class.
For example <code snipped> The TypeName() function returns the name of the class itself, in this case
"MyClass". What I'm looking for is a class internal method that will return the name of the instance variable.


There is no function for this, however you could easily add a new property
of your object that would be set when the object is created and could be
queried later.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Nov 21 '05 #3
Mike D Sutton wrote:
Is there a way in VB 6 (and VB 2005) to get the instance name from a
class. For example

<code snipped>
The TypeName() function returns the name of the class itself, in
this case "MyClass". What I'm looking for is a class internal
method that will return the name of the instance variable.


There is no function for this, however you could easily add a new
property of your object that would be set when the object is created
and could be queried later.


Yeah, good idea -- I often add a .Tag property to my objects, for this sort of use.
--
Working Without a .NET?
http://classicvb.org/petition
Nov 21 '05 #4
Michael D. Ober wrote:
Is there a way in VB 6 (and VB 2005) to get the instance name from a
class. For example

class MyClass
'some methods and properties
public property get VarName() as string
VarName = somefunction(me)
end property

end class
dim myVar as MyClass
Set myVar = new MyClass
debug.print myVar.VarName

The output would be "myVar"


What would you have it show if the code above continued:

Dim myVar2 as MyClass
Set myVar2 = myVar
Debug.Print myVar.VarName; ", "; myVar2.VarName

As others have said, provide a (write once) property yourself.

[In VB.NET you can set it in the constructor:

Set myVar = New MyClass("myVar")
]

--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)
Nov 21 '05 #5
Mark Hurd wrote:
[In VB.NET you can set it in the constructor:

Set myVar = New MyClass("myVar")
]


Perhaps, but how might one do it in Groovy?
--
Working Without a .NET?
http://classicvb.org/petition
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinasalek | last post by:
class TTest { function instance_name() { echo "instance name : $instance_name"; } } $test=new TTest(); $text->instance_name();
8
by: Matthew Bell | last post by:
Hi, I've got a question about whether there are any issues with directly calling attributes and/or methods of a threaded class instance. I wonder if someone could give me some advice on this. ...
3
by: Guy Robinson | last post by:
Hello, I have a list of class instances. I wish to get the appropriate class attribute in each class instance depending on a SINGLE keyword in the calling class. How do I get the calling...
80
by: Bibby | last post by:
Hi, I'm interested in getting started in the programming world. I've dabbled in C, C++ and VB6. Which would be the best language to focus my attention to regarding the following considerations: ...
7
by: Steven.Xu | last post by:
Hello everyone! I have a problem about create an instance automatically in C#. Now I have a class: namespace1.namespace11.CClass01. I want to create it's instance in a function named...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
2
by: Wouter de Kort | last post by:
I've started looking at Aspect Oriented Programming but I've stumbled at a problem I can't solve. I want to add an Aspect that would notify a UnitOfWork that the current DomainObject has changed...
20
by: Shawnk | last post by:
I would like to get the class INSTANCE name (not type name) of an 'object'. I can get the object (l_obj_ref.GetType()) and then get the (l_obj_typ.Name) for the class name. I there any way of...
2
by: Daniel Lipovetsky | last post by:
I would like for an object to "report" to a container object when a new instance is created or deleted. I could have a container object that is called when a new instance is created, as below. ...
3
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.