How to know instance name?

  • Thread starter Thread starter Angel Mateos
  • Start date Start date
A

Angel Mateos

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!
 
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
 
sorry but what I want to know is the name of the variable that has
instanciated the class

Thanks
 
"Angel Mateos" <[email protected]> a écrit dans le message de (e-mail address removed)...

| 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
 
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...
 
Back
Top