|
-
Oct 16th, 2006, 08:24 AM
#1
Thread Starter
Fanatic Member
Getting variable names
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 )
-
Oct 16th, 2006, 08:46 AM
#2
Re: Getting variable names
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.
VB Code:
Dim obj1 As Object = New Object
Dim obj2 As Object = obj1
Dim obj3 As Object = obj2
Now you have three variables and one object with no name.
-
Oct 16th, 2006, 10:07 AM
#3
Thread Starter
Fanatic Member
Re: Getting variable names
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?
-
Oct 16th, 2006, 01:49 PM
#4
Re: Getting variable names
it creates a new object (obj4) and set's it equal to what obj3 is
but obj4 is a new object sperate of obj3
-
Oct 16th, 2006, 01:54 PM
#5
Re: Getting variable names
 Originally Posted by JuggaloBrotha
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)
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 16th, 2006, 05:37 PM
#6
Re: Getting variable names
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 [U]New[/U] Object
This does the same:
VB Code:
Dim obj As Object = [U]New[/U] Object
This also does the same:
VB Code:
Dim obj As Object
obj = [U]New[/U] Object
This 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 obj1 As New Object
Dim obj2 As New Object
obj2 = obj1
In 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.
-
Oct 17th, 2006, 01:30 AM
#7
Re: Getting variable names
i had neglected that jm, it's java that would create a new object with the same value(s) as the previous object
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|