The Internet Encyclopedia (Volume 3)

(coco) #1

P1: JDT


WL040C-44 WL040/Bidgoli-Vol III-Ch-51 June 23, 2003 16:33 Char Count= 0


630 VISUALBASICSCRIPTINGEDITION(VBSCRIPT)

objMyAtt.value = "text"
objMyTag.Attributes.setNamedItem (objMyAtt)
set objMyAtt = Window.Document.CreateAttribute("name")
objMyAtt.value = "otherColor"
objMyTag.Attributes.setNamedItem (objMyAtt)
set objMyAtt = Window.Document.CreateAttribute("id")
objMyAtt.value = "OtherColorTextbox"
objMyTag.Attributes.setNamedItem (objMyAtt)
else
if Window.Document.myForm.childNodes.length = 5 then
Window.Document.All.Item("OtherColorLabel").RemoveNode(True)
Window.Document.All.Item("OtherColorTextbox").RemoveNode(True)
end if
end if
end sub
</script></head>
<body>
<form name='myForm' action=" method='Get'>
<h3>Pick a color</h3>
<select id='myMenu' name='color'></select>
</form></body></html>

ADVANCED FEATURES OF VBSCRIPT
Object classes enable encapsulation of programming
code, which in turn facilitates modular development of
applications and the reuse of code. While VBScript has
long provided stable support for the use of object classes
by script (i.e., since VBScript version 2), mechanisms
to support modular development and reuse of script it-
self were less stable and less robust prior to the release
of VBScript version 5. VBScript now provides several
ways of varying complexity and sophistication to modu-
larize script development and deployment and facilitate
script reuse. Discussed briefly in this section are three
specific technologies that facilitate script modularization
and reuse: Windows Script Files, Remote Scripting, and
Windows Script Components. In addition, VBScript, as
of version 5, supports class declaration statements, and
these statements allow for the direct creation of full-
blown object classes written entirely in VBScript. Class
declarations are mentioned here in the context of remote
scripting, but a more complete discussion of authoring
generic classes using VBScript is beyond the scope of this
chapter.

Windows Script Files
Windows Script Files (typical extension.wsf) are XML
files that facilitate the simple modularization and reuse
of scripts written for WSH. Windows Script Files con-
tain a mix of script, contained in <Script> elements, and
XML elements that define the flow and use of both inter-
nally contained script as well as script contained in exter-
nal files (e.g., files with extensions such as .vbs, .pl, and
.js). Windows Script Files allow script authors to incor-
porate libraries of previously written script functions and
subprocedures into current projects and jobs. Windows
Script Files support the development and deployment of
individual script applications that use multiple scripting
engines (i.e., are written in multiple scripting languages)

and the import of type libraries associated with external
objects and containing reusable constant declarations rel-
evant to those objects. Windows Script Files can be cre-
ated or edited using a standard XML or plain text edi-
tor, and single files may contain instructions for multi-
ple script jobs or projects. Files with extension.wsf are
automatically associated with the WSH. They can be in-
voked from either the command line or the Windows Run
dialog. Command line switches are available that allow
the user to run Windows Script Files in batch mode (i.e.,
suppresses error messages, MsgBox dialogs, InputBox di-
alogs, etc.), in debug mode, and with a time-out. Com-
mand line switches also allow a user to specify scripting
engine to use and which job to run (for a multijob Win-
dows Script File). Windows Script Files are further de-
scribed, including examples, on the Microsoft MSDN Web
site (Microsoft, 2002a) under Web Development, Script-
ing, Documentation, Windows Script Technologies, Win-
dows Script Host, Running Your Scripts.

Remote Scripting
Remote scripting has been available to JScript program-
mers for some time, and most extant examples available
today rely on JScript. However, the inclusion of the class
declaration statement in VBScript version 5 means that
this technology is now also available to VBScript pro-
grammers (Clinick, 1999). Remote scripting is an im-
plementation by which client-side scripts running in the
context of a Web browser (e.g., Internet Explorer) can
call methods of objects written in server-side script (i.e.,
methods of ASP pages running in context of IIS), or if
preferred, can actually instantiate ASP pages running on
the server as objects in client-side script. For this to work,
the VBScript on the ASP page must define a class and
then communicate its availability to the Remote Script-
ing Runtime. It does so by creating an object named
publicdescription, initializing that object as an instance
Free download pdf