VBScript does not provide any include directive that is common in many other languages. Luckily, the language provides a pseudo-include statement, EXECUTEGLOBAL and EXECUTE, which we can use to fake the include directive.
Why do we need to do that in our scripts? Well, very often, we want to distribute a standard set of codes, for example, templated functions and procedures. You want to ensure that all your scripts are running from the same versions. If those functions are included inside the vbscript, then it will be impossible to control your standard functions’ version.
A real life example: I have a report class which is used by various Start of Day (SOD) scripts to provide a summary text file about their status. I don’t want to copy the codes into each script and have to update every script everytime I add or update the function of the class. Includes come in handy in this case.
I created a function that would read the file to be included and use EXECUTEGLOBAL to fake the include. You only need to copy this function into all the scripts that you intend to use include statements once. In all the headers of your script, you can add the following line:
In your script you should have this function:
dim fso, txt
Set fso = CreateObject(“Scripting.FileSystemObject”)
set txt = fso.OpenTextFile(FileToInclude, 1)
GetIncludeFile = txt.ReadAll
set txt = Nothing
set fso = Nothing