How to know instance name?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angel Mateos

    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!


  • Patrice

    #2
    Re: How to know instance name?

    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" <amateos@nospam .es> a écrit dans le message de news:
    OS9Ms7QkGHA.100 0@TK2MSFTNGP04. phx.gbl...[color=blue]
    > 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!
    >[/color]


    Comment

    • Angel Mateos

      #3
      Re: How to know instance name?

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

      Thanks




      "Patrice" <scribe@chez.co m> escribió en el mensaje
      news:eaHuneRkGH A.1204@TK2MSFTN GP02.phx.gbl...[color=blue]
      > 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" <amateos@nospam .es> a écrit dans le message de news:
      > OS9Ms7QkGHA.100 0@TK2MSFTNGP04. phx.gbl...[color=green]
      >> 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!
      >>[/color]
      >
      >[/color]


      Comment

      • Joanna Carter [TeamB]

        #4
        Re: How to know instance name?

        "Angel Mateos" <amateos@nospam .es> a écrit dans le message de news:
        ufqWAuRkGHA.330 4@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


        Comment

        • Patrice

          #5
          Re: How to know instance name?

          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" <amateos@nospam .es> a écrit dans le message de news:
          ufqWAuRkGHA.330 4@TK2MSFTNGP03. phx.gbl...[color=blue]
          > sorry but what I want to know is the name of the variable that has
          > instanciated the class
          >
          > Thanks
          >
          >
          >
          >
          > "Patrice" <scribe@chez.co m> escribió en el mensaje
          > news:eaHuneRkGH A.1204@TK2MSFTN GP02.phx.gbl...[color=green]
          >> 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" <amateos@nospam .es> a écrit dans le message de news:
          >> OS9Ms7QkGHA.100 0@TK2MSFTNGP04. phx.gbl...[color=darkred]
          >>> 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!
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          Working...