Reusable Code Libraries
We’ve now discussed all of the basic principles of structuring VBScript programs, of constructing subroutines that can be used by various parts of your program, of building functions that perform calculations and other manipulations and pass the result back to the calling part of the program, and of creating classes that allow you to encapsulate real-world processes and objects. The emphasis on subroutines, functions, and classes, though, raises another issue—that of code reuse. Typically, classes are defined so that they can be used in a variety of applications. Similarly, many subroutines and functions are intended not only to reduce code in a single application, but also to be “black boxes” that can provide some service to multiple applications.
Although it generally hasn’t been emphasized, and is dependent on the host platform, VBScript code can be reused on three of the four host platforms discussed here. The only platform that doesn’t support code reuse is Outlook forms. That means that if you’re scripting for WSH, ASP, or MSIE, you can develop code libraries that you import into your script.
Active Server Pages
You can import HTML, client-side
script, or server-side script into an ASP file by using the
#include
server-side directive. Its syntax is:
<!-- #includePathType
=sFileName
-->
where PathType
is one of the following
keywords:
-
File
Indicates that
sFileName
is relative path from the current directory-
Virtual
Indicates that
sFileName
is a full ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.