Re: Difference between NEW and CREATEOBJECT?

From: Tom Ogilvy (twogilvy_at_msn.com)
Date: 02/19/04


Date: Thu, 19 Feb 2004 09:26:32 -0500

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" <no@email.com> wrote in message
news:c1289e$bed$1@news.net.uni-c.dk...
> Thanks for the detailed answer
> I will then use new as often as i can
>
> Regards
> Mark
>
> "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
> news:%23F6$pit9DHA.1948@TK2MSFTNGP12.phx.gbl...
> > 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 Tools>References 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" <no@email.com> wrote in message
> > news:c122hd$8oq$1@news.net.uni-c.dk...
> > > 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
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Difference between NEW and CREATEOBJECT?
    ... When you declare something As the particular ... > type, and use the New keyword, you are telling the compiler to go through ... > compiler has to go through the IUnknown interface. ...
    (microsoft.public.excel.programming)
  • Re: MFC and c++ problems
    ... compiler to generate code that is architecturally nonsensical. ... So a design in which a control has any syntactic knowledge of any container of itself ... GetParent->SendMessage is the interface of choice, ...
    (microsoft.public.vc.mfc)
  • Re: Win32 API and gfortran
    ... write out a module containing only interface blocks and compile the ... that the /iface switches and ATTRIBUTES directives change the compiler ... arguments are passed in the normal Fortran way ...
    (comp.lang.fortran)
  • Re: Using early-bound interface on a late-bound object
    ... > the compiler determines which interfaces to use, ... > supports the declared interface. ... >> help if someone can point me to some authoritative document or reference ... within customer shops when they mirrored this 'division' to keep their ...
    (microsoft.public.vb.general.discussion)
  • Re: object system...
    ... in a statically compiled app, all of the type information is known at ... compiler starts integrating itself with the outside world, ... produces the result, the type or interface. ... optimizations the ...
    (comp.object)

Loading