Re: CreateObject in VBscript by mayayana
mayayana
Mon May 23 09:10:28 CDT 2005
> Is there some restriction on using CreateObject() in VBScript in web
pages?
Yes. If an object is not marked safe for scripting,
or if ActiveX is disabled, it won't work. Depending on
the setting for "Initialize and script ActiveX controls
not marked as safe" you may get a warning or it may
just not work. If it didn't work that way then website would
be able to access your files from online....or rather, they'd
be able to access your files *without* needing to exploit
a bug in IE.
(There may also be further complications in XP
SP2. I'm not sure about that offhand when it comes to
a client page not in the local zone.)
> Can someone explain the difference between CreateObject() in VBscript and
> Visual Basic? In both cases I would like to open PowerPoint on the client
> PC.
They're basically the same, but CreateObject is a
very inefficient way to go in VB. CreateObject is
"late binding". It looks up the type library for the object
in the Registry, based on the ProgID, in order to
find the addresses of functions in the object.
In VB you can use "early binding", in which the type
library is linked into your EXE by setting a reference
to it in Project -> References. The difference in code
is minimal but the difference in how it works is significant.
To use early binding in VB, set your reference in
Project -> References (which will also give you an
"intellisense" menu and info. in the Object Browser),
declare the object specifically, then use the New operator:
Dim OPP as powerpoint.application
Set OPP = New powerpoint.application
'-- do the PP code
Set OPP = Nothing
(Note that it may not be the exact same syntax. The
early binding declare might be PowerPoint, for instance,
instead of PowerPoint.Application. It should be clear
what to use in the Intellisense menu that shows as soon
as you type a space after "New".)