|
-
Dec 3rd, 2002, 09:31 PM
#1
Thread Starter
Sleep mode
little confusing!![resolved]
What's the difference between these two lines , they give the same result though.
VB Code:
dim object as new baseclass
'and
object= new baseclass
Last edited by Pirate; Dec 4th, 2002 at 05:10 PM.
-
Dec 3rd, 2002, 10:03 PM
#2
Member
The top one declared a new variable then creates an Object in memory, then points the variable to that Object.
The bottom one simply creates an Object in memory then points a previously created variable to it.
Dim o As New Object is just short for Dim o As Object = New Object.
-
Dec 3rd, 2002, 10:17 PM
#3
Thread Starter
Sleep mode
oh God , I completely got stuck.
if you'r right ,so why MS duplicates the way it declares variables then???
-
Dec 3rd, 2002, 11:11 PM
#4
What do you mean 'why MS duplicates the way it declares variables?'
Those are two different things. Lets say you have been working with an object and now you want to reuse the same variable but start a new object well there is not reason to dim or create a new variable to hold the new object just reuse the old one.
You are thinking of
Dim o As New BaseClass
As 1 thing but its not its 2
the Dim and New commands are seperate commands they are just often used together. Dim creates a new variable. New initializes a new instance of an object.
-
Dec 4th, 2002, 09:48 AM
#5
it just a matter of when you want to bond the variable to something
There are mutiple ways to do this all depending on when and where you want to specify a New or existing object into that variable
Dim a As Object
Dim b As New Object
now say you want a to = b then that is why the line a = New Object is valid becasue you are assigning a to something else wether it is a new object or an existing one..in which case you would say a = b
if you coldnt do
a = New Object
then you also couldnt do
a = b
Get it?
-
Dec 4th, 2002, 10:08 AM
#6
Thread Starter
Sleep mode
wow , perfectly integrated in my mind.wyrd maybe couldn't explain that well , so that messed me up!
thanx a lot Edneeis and Cander
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
|