473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to know instance name?

Is posible something like this?

public Class Class1
property readonly InstanceName
get
return me.InstanceName
endget
end property
end class

(...)

dim MyVariable as Class1
msgbox class1.Instance Name -> shows MyVariable

(..)
Thanks!
Jun 16 '06 #1
4 1609
Just return a private member instead of calling the property again. Here you
call the property to returns the property value resulting in recursive
calls...

The example taken from the doc sis:
Class Class1
' Define a local variable to store the property value.
Private PropertyValue As String
' Define the property.
Public Property Prop1() As String
Get
' The Get property procedure is called when the value
' of a property is retrieved.
Return PropertyValue
End Get
Set(ByVal Value As String)
' The Set property procedure is called when the value
' of a property is modified.
' The value to be assigned is passed in the argument to Set.
PropertyValue = Value
End Set
End Property
End Class
--
Patrice

"Angel Mateos" <am*****@nospam .es> a écrit dans le message de news:
OS************* *@TK2MSFTNGP04. phx.gbl...
Is posible something like this?

public Class Class1
property readonly InstanceName
get
return me.InstanceName
endget
end property
end class

(...)

dim MyVariable as Class1
msgbox class1.Instance Name -> shows MyVariable

(..)
Thanks!

Jun 16 '06 #2
sorry but what I want to know is the name of the variable that has
instanciated the class

Thanks


"Patrice" <sc****@chez.co m> escribió en el mensaje
news:ea******** ******@TK2MSFTN GP02.phx.gbl...
Just return a private member instead of calling the property again. Here
you call the property to returns the property value resulting in recursive
calls...

The example taken from the doc sis:
Class Class1
' Define a local variable to store the property value.
Private PropertyValue As String
' Define the property.
Public Property Prop1() As String
Get
' The Get property procedure is called when the value
' of a property is retrieved.
Return PropertyValue
End Get
Set(ByVal Value As String)
' The Set property procedure is called when the value
' of a property is modified.
' The value to be assigned is passed in the argument to Set.
PropertyValue = Value
End Set
End Property
End Class
--
Patrice

"Angel Mateos" <am*****@nospam .es> a écrit dans le message de news:
OS************* *@TK2MSFTNGP04. phx.gbl...
Is posible something like this?

public Class Class1
property readonly InstanceName
get
return me.InstanceName
endget
end property
end class

(...)

dim MyVariable as Class1
msgbox class1.Instance Name -> shows MyVariable

(..)
Thanks!


Jun 16 '06 #3
"Angel Mateos" <am*****@nospam .es> a écrit dans le message de news:
uf************* *@TK2MSFTNGP03. phx.gbl...

| sorry but what I want to know is the name of the variable that has
| instanciated the class

Variables don't have "names", the word you see in the code is simply for
your convenience; the reality is that the compiler knows variables as
addresses in memory.

It would certainly be impossible for a class to be able to return any one
name, as there could be thousands of instances of the same class.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 16 '06 #4
Not sure to understand (a variable doesn't instanciate a class, code does).

IMO your best bet is to explain us what you are trying to do (non
technically) so that one can suggest a solution. If you meant you would like
to know the name of a variable that "represents " a class instance this is
AFAIK not possible (names are just programming "symbols" for human, the
computer uses a pointer) plus you could have multiple variables etc...
referencing the same instance.

Explain rather what you are trying to do...

--
Patrice

"Angel Mateos" <am*****@nospam .es> a écrit dans le message de news:
uf************* *@TK2MSFTNGP03. phx.gbl...
sorry but what I want to know is the name of the variable that has
instanciated the class

Thanks


"Patrice" <sc****@chez.co m> escribió en el mensaje
news:ea******** ******@TK2MSFTN GP02.phx.gbl...
Just return a private member instead of calling the property again. Here
you call the property to returns the property value resulting in
recursive calls...

The example taken from the doc sis:
Class Class1
' Define a local variable to store the property value.
Private PropertyValue As String
' Define the property.
Public Property Prop1() As String
Get
' The Get property procedure is called when the value
' of a property is retrieved.
Return PropertyValue
End Get
Set(ByVal Value As String)
' The Set property procedure is called when the value
' of a property is modified.
' The value to be assigned is passed in the argument to Set.
PropertyValue = Value
End Set
End Property
End Class
--
Patrice

"Angel Mateos" <am*****@nospam .es> a écrit dans le message de news:
OS************* *@TK2MSFTNGP04. phx.gbl...
Is posible something like this?

public Class Class1
property readonly InstanceName
get
return me.InstanceName
endget
end property
end class

(...)

dim MyVariable as Class1
msgbox class1.Instance Name -> shows MyVariable

(..)
Thanks!



Jun 16 '06 #5

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

Similar topics

5
4957
by: sinasalek | last post by:
class TTest { function instance_name() { echo "instance name : $instance_name"; } } $test=new TTest(); $text->instance_name();
6
22514
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
3
2516
by: john | last post by:
I have a situation where i have a base class and a sub-class. A null instance of the sub-class is passed into a function. The function needs to create a new instance of the sub-class, but the function only has knowledge of the base class, not the sub-class So is there a way to get the function to create a new instance of the sub-class without actually using 'new SubClass() Let me demonstrate what i want to do. Below, in my situation,...
4
1153
by: Sam Martin | last post by:
I want to get a property's name from the property. e.g. not this.... this.txtField.DataBindings.Add("Text", myObject,"MyFieldOrProperty"); but this.... this.txtEmail.DataBindings.Add("Text", myObject,<someway of getting name of MyObject.MyFieldOrProperty without using literal>); TIA
161
7806
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that
20
27770
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 getting 'l_Fred_my_ins' out of the following. .... My_cls l_Fred_my_ins = new My_cls();
2
1300
by: pipehappy | last post by:
Hello: Is it possible for an instance know its name used by other part of program. I mean like this: class test: def __init__(self): pass when some one writes
2
5498
by: Mesan | last post by:
Hello everyone, Thanks to many useful posts in this newsgroup and others, I've been able to come very close to something I've been wanting to do for a very long time. I've figured out how to create a new custom protocol handler in Windows to handle locations like "myProtocol:", which lets me have a shortcut pointing to "myProtocol:myPrimaryKey" and have my application automatically open and display the given account. That's great. I
2
1997
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. class AnyObject: pass class Container: links = def add(self,other):
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.