472,989 Members | 2,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1575
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
by: sinasalek | last post by:
class TTest { function instance_name() { echo "instance name : $instance_name"; } } $test=new TTest(); $text->instance_name();
6
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
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
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
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
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: 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
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
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. ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.