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
sFileNameis relative path from the current directory-
Virtual Indicates that
sFileNameis a full ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access