PDA

Click to See Complete Forum and Search --> : little confusing!![resolved]


Pirate
Dec 3rd, 2002, 08:31 PM
What's the difference between these two lines , they give the same result though.


dim object as new baseclass
'and

object= new baseclass

wyrd
Dec 3rd, 2002, 09:03 PM
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.

Pirate
Dec 3rd, 2002, 09:17 PM
oh God , I completely got stuck.:confused:
if you'r right ,so why MS duplicates the way it declares variables then???

Edneeis
Dec 3rd, 2002, 10:11 PM
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.

Cander
Dec 4th, 2002, 08:48 AM
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?

Pirate
Dec 4th, 2002, 09:08 AM
wow , perfectly integrated in my mind.wyrd maybe couldn't explain that well , so that messed me up!:rolleyes:
thanx a lot Edneeis and Cander;)