468,247 Members | 1,331 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

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 1430
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by john | last post: by
4 posts views Thread by Sam Martin | last post: by
161 posts views Thread by KraftDiner | last post: by
2 posts views Thread by pipehappy | last post: by
2 posts views Thread by Daniel Lipovetsky | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.