Sub Include(sScriptPathspec)
ExecuteGlobal CreateObject("Scripting.FileSystemObject")_
.OpenTextFile(sScriptPathspec).ReadAll
End Sub
This has been posted in various forms by different people from time to time ever since VBScript 5.0
was released (which is the first release that supports ExecuteGlobal).
A word of advice... Only include script using this technique that has been thoroughly debugged
independently with robust error handling. Debugging dynamically executed script can be pretty
tricky.
I would actually recommend that you consider encapsulating common script code in a WSC (Windows
Script Component)...
WSC Tutorial
http://msdn.microsoft.com/scripting/scriptlets/doc/lettitle.htm
WSC Documentation
http://msdn.microsoft.com/scripting/scriptlets/serverdocs.htm
http://msdn.microsoft.com/scripting/scriptlets/wscdoc.exe
--
Michael Harris
Microsoft.MVP.Scripting
--
Please do not email questions - post them to the newsgroup instead.
--
Quote:
> OK, I get it! Thanks for your help. Now if this only worked when using
> VBScript in applications....
> > I'm not sure I understand your question.
> > You can make a Windows Scripting File (.WSF)
> > which can "include" other files(any scripting language files that the
> > platform supports; perl,jscript,python....)
> > 'this line of the .wsf is an example of how to include
> > <script language="JScript" src="FSO.JS"/>
> > put the fso.js file in the same place as the .wsf
> > Hope this helps
> > > How would this work just using the wscript and/or cscript commands? Do
> I
> > > just create two files and stick them in my directory then invoke one?
> > > > ' This is an include example for a .wsf
> > > > ' Make section this a .wsf file
> > > > <Job id="IncludeExample">
> > > > <script language="JScript" src="FSO.JS"/>
> > > > <script language="VBScript">
> > > > ' Get the free space for drive C.
> > > > s = GetFreeSpace("c:")
> > > > WScript.Echo s
> > > > </Script>
> > > > </Job>
> > > > ' and make this a FSO.JS file that will be included
> > > > function GetFreeSpace(drvPath) {
> > > > var fs, d, s;
> > > > fs = new ActiveXObject("Scripting.FileSystemObject");
> > > > d = fs.GetDrive(fs.GetDriveName(drvPath));
> > > > s = "Drive " + drvPath + " - " ;
> > > > s += d.VolumeName;
> > > > s += " Free Space: " + d.FreeSpace/1024 + " Kbytes";
> > > > return s;
> > > > }
> message
> > > > > I'm writing an vb script to run using the scripting host.
> > > > > Is there any way I can include a file in the code like you can in
> asp?
> > > > > Thanks
> > > > > JM