473,503 Members | 1,650 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.InstanceName -> shows MyVariable

(..)
Thanks!
Jun 16 '06 #1
4 1596
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.InstanceName -> 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.com> escribió en el mensaje
news:ea**************@TK2MSFTNGP02.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.InstanceName -> 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.com> escribió en el mensaje
news:ea**************@TK2MSFTNGP02.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.InstanceName -> 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
4948
by: sinasalek | last post by:
class TTest { function instance_name() { echo "instance name : $instance_name"; } } $test=new TTest(); $text->instance_name();
6
22489
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...
3
2507
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...
4
1143
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",...
161
7684
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.....
20
27729
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
1291
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
5483
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...
2
1966
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. ...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
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...
1
6988
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...
0
7456
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...
0
5578
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,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
379
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...

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.