Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Difference between NEW and CREATEOBJECT?

Hi NG

Just a newbie question.

What is the difference between NEW and CREATEOBJCT ?

The following two lines of code seems to do the same!

Set xmlStr = CreateObject("Microsoft.XMLDOM")
Set xmlStr = New DOMDocument

Is there any performance issues in using the one instead of the other?

Regards
Mark


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Difference between NEW and CREATEOBJECT?

Mark,
New uses early binding. When you declare something As the particular object
type, and use the New keyword, you are telling the compiler to go through
the specific library interface to that object. Because you've referenced
this in the VBA ToolsReferences settings, the compiler can read the typelib
file, and knows how to "talk" to that object. Because this is done at
compile time, not run time, execution is much faster.

CreateObject uses late-binding. When you declare something As Object and use
CreateObject, VBA has no idea what object you're dealing with. Thus, the
compiler has to go through the IUnknown interface. This returns an array of
pointers to all the other interfaces supported by the object. Once those
interface pointers are known, VBA then goes through IDispatch to determine
the specific property or method to actually call .All of this takes a great
deal of system overhead and can make your code execute substantially slower.

In Summary, New is quicker, and provides IntelliSense when developing, but
requires the type library to be linked.joined/referenced (whatever you want
to call it) to your project. CreateObject is slower, requires more on the
developer's part (you need to know library constant values for instance),
but can be more flexible, especially when distributing to multiple platforms
where there may be different versions of the library.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mark" wrote in message
...
Hi NG

Just a newbie question.

What is the difference between NEW and CREATEOBJCT ?

The following two lines of code seems to do the same!

Set xmlStr = CreateObject("Microsoft.XMLDOM")
Set xmlStr = New DOMDocument

Is there any performance issues in using the one instead of the other?

Regards
Mark




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Difference between NEW and CREATEOBJECT?

Thanks for the detailed answer
I will then use new as often as i can

Regards
Mark

"Bob Phillips" wrote in message
...
Mark,
New uses early binding. When you declare something As the particular

object
type, and use the New keyword, you are telling the compiler to go through
the specific library interface to that object. Because you've referenced
this in the VBA ToolsReferences settings, the compiler can read the

typelib
file, and knows how to "talk" to that object. Because this is done at
compile time, not run time, execution is much faster.

CreateObject uses late-binding. When you declare something As Object and

use
CreateObject, VBA has no idea what object you're dealing with. Thus, the
compiler has to go through the IUnknown interface. This returns an array

of
pointers to all the other interfaces supported by the object. Once those
interface pointers are known, VBA then goes through IDispatch to determine
the specific property or method to actually call .All of this takes a

great
deal of system overhead and can make your code execute substantially

slower.

In Summary, New is quicker, and provides IntelliSense when developing, but
requires the type library to be linked.joined/referenced (whatever you

want
to call it) to your project. CreateObject is slower, requires more on the
developer's part (you need to know library constant values for instance),
but can be more flexible, especially when distributing to multiple

platforms
where there may be different versions of the library.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mark" wrote in message
...
Hi NG

Just a newbie question.

What is the difference between NEW and CREATEOBJCT ?

The following two lines of code seems to do the same!

Set xmlStr = CreateObject("Microsoft.XMLDOM")
Set xmlStr = New DOMDocument

Is there any performance issues in using the one instead of the other?

Regards
Mark






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Difference between NEW and CREATEOBJECT?

Of course the reason to use late binding in a distributed file is to avoid
conflicts with library versions and locations. So your code doesn't error
out when the file is opened.

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
Thanks for the detailed answer
I will then use new as often as i can

Regards
Mark

"Bob Phillips" wrote in message
...
Mark,
New uses early binding. When you declare something As the particular

object
type, and use the New keyword, you are telling the compiler to go

through
the specific library interface to that object. Because you've referenced
this in the VBA ToolsReferences settings, the compiler can read the

typelib
file, and knows how to "talk" to that object. Because this is done at
compile time, not run time, execution is much faster.

CreateObject uses late-binding. When you declare something As Object and

use
CreateObject, VBA has no idea what object you're dealing with. Thus, the
compiler has to go through the IUnknown interface. This returns an array

of
pointers to all the other interfaces supported by the object. Once those
interface pointers are known, VBA then goes through IDispatch to

determine
the specific property or method to actually call .All of this takes a

great
deal of system overhead and can make your code execute substantially

slower.

In Summary, New is quicker, and provides IntelliSense when developing,

but
requires the type library to be linked.joined/referenced (whatever you

want
to call it) to your project. CreateObject is slower, requires more on

the
developer's part (you need to know library constant values for

instance),
but can be more flexible, especially when distributing to multiple

platforms
where there may be different versions of the library.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mark" wrote in message
...
Hi NG

Just a newbie question.

What is the difference between NEW and CREATEOBJCT ?

The following two lines of code seems to do the same!

Set xmlStr = CreateObject("Microsoft.XMLDOM")
Set xmlStr = New DOMDocument

Is there any performance issues in using the one instead of the other?

Regards
Mark








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CreateObject("Excel.Application") Olivia Towery Excel Worksheet Functions 4 June 12th 06 12:07 AM
Createobject returns null in Excel [email protected] Excel Discussion (Misc queries) 1 March 27th 06 04:04 AM
CreateObject("Excel.Application") - Access denied Luca[_2_] Excel Programming 0 February 6th 04 01:21 PM
Templates and CreateObject John Excel Programming 1 October 29th 03 01:07 PM
CreateObject produces error Robert Chapman Excel Programming 0 August 15th 03 03:48 PM


All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"