Windows Scripting
  Home arrow Windows Scripting arrow Page 6 - Using Includes in VBScript
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Using Includes in VBScript
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-03-27

    Table of Contents:
  • Using Includes in VBScript
  • Building the basic routine.
  • Executing the external code
  • Allowing for relative or absolute path names
  • Allowing for platform-specific paths
  • Testing the subroutine

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Includes in VBScript - Testing the subroutine


    (Page 6 of 6 )

    We’re going to create two files.  The first one, called test.vbs, will be our test script and the second one, called include.vbs, will contain our include code.  The first should look like this:

    ' test.vbs

     

    Import "include.vbs"

     

    Sub Import(ByVal strFile)

       Set objFs = CreateObject("Scripting.FileSystemObject")

       Set WshShell = CreateObject("WScript.Shell")

       strFile = WshShell.ExpandEnvironmentStrings(strFile)

       file = objFs.GetAbsolutePathName(strFile)

       Set objFile = objFs.OpenTextFile(strFile)

       strCode = objFile.ReadAll

       objFile.Close

       ExecuteGlobal(strCode)

    End Sub

    Our include file is going to be very simple.  We’ll just use the Wscript Echo method to create a “Hello World” script.

    ' include.vbs

     

    Wscript.Echo "Hello World!"

    Save both files to the same folder and double click test.vbs.  Just like magic, you should get a VBScript message box saying “Hello World!”.

    There you have it.  A simple subroutine that you can reuse in any of your scripts to add file include capabilities to VBScript.  I like to use this to include reusable classes.  This way, if I make updates to those classes I can easily update all of my other scripts as well without having to update each one individually.

    I hope that you have found this solution as helpful as I did.  Find ways to customize it or expand upon it to make it fit your own needs.  That’s all for me this time.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Everyone loves a good workaround. This one lets you take advantages of code...
     

    WINDOWS SCRIPTING ARTICLES

    - A Portable Scripting Toolbox
    - WPF Through an Example: Introduction
    - Beginning SharePoint Web Part Development
    - More Alternative Languages for WSH
    - WPF Control Layout
    - WSH in Other Languages
    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway