I know that Me.Name gets the name of the class of a variable, but is there
a way to get the name of an instance of an object if for some reason you don't know it ? ( like in a form or something, using Me.somemethod )
Printable View
I know that Me.Name gets the name of the class of a variable, but is there
a way to get the name of an instance of an object if for some reason you don't know it ? ( like in a form or something, using Me.somemethod )
Instances of classes don't have names unless they have a Name property. Controls have a Name property and it will be the same as the name of the variable used to identify them by default if you create them in the designer, but you can change or clear the value of the Name property, or you can create controls with a blank Name property, or you can assign the same control to multiple variables, or you can assign Nothing to a variable. I'm guessing that you're talking about a variable name but the variable is not the object.Now you have three variables and one object with no name.VB Code:
Dim obj1 As Object = New Object Dim obj2 As Object = obj1 Dim obj3 As Object = obj2
So all three variables, obj1, obj2, obj3, point to the same object? If you modify one, you modify them all, correct?
What if I use 'New', for example:
Dim obj4 As New Object = obj3
What happens then?
it creates a new object (obj4) and set's it equal to what obj3 is
but obj4 is a new object sperate of obj3
Actually no, it'll create a new Object but then obj4 will reference the same object as obj3 and the Newly created object won't be in use (Freed by the Garbage Collector)Quote:
Originally Posted by JuggaloBrotha
Actually nothing will happen because that code will not compile. You can't declare a variable as a new object and then assign another object on the same line. Whenever you use the word "New" you're creating a new object. Whenever you use an equals sign you're assigning the object returned by the expression on the right to the reference on the left.
This declares a variable but creates no object, so the variable refers to Nothing:This declares a variable, creates a new object and assigns it to the variable:VB Code:
Dim obj As ObjectThis does the same:VB Code:
Dim obj As [U]New[/U] ObjectThis also does the same:VB Code:
Dim obj As Object = [U]New[/U] ObjectThis creates two objects and assigns them to newly declared variables, then assigns one of the objects to the other variable too, thus the other object is lost:VB Code:
Dim obj As Object obj = [U]New[/U] ObjectIn the last example, obj2 now refers to the same object as obj1 and the object that obj2 did refer to is inaccessible because you don't have a variable that refers to it.VB Code:
Dim obj1 As New Object Dim obj2 As New Object obj2 = obj1
i had neglected that jm, it's java that would create a new object with the same value(s) as the previous object