Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - 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 - Allowing for relative or absolute path names


    (Page 4 of 6 )

    First things first, I want this code to work with either absolute or relative file paths.  To do that, we’re going to add a single line before trying to open the input file.

    Sub Import(strFile)

       Set objFs = CreateObject("Scripting.FileSystemObject")

       strFile = objFs.GetAbsolutePathName(strFile)

       Set objFile = objFs.OpenTextFile(strFile)

       strCode = objFile.ReadAll

       objFile.Close

       ExecuteGlobal strCode

    End Sub

    In this line, I use the FileSystemObject’s GetAbsolutePathName to reassign the strFile variable with a full path to the file to be included.  What’s nice is how the GetAbsolutePathName works in this particular case.

    If you are using a script editor with a debugger to test this script, it may fail at this point.  This is because most debuggers will not execute your code from the directory where your script resides.  If this happens, try hard coding a path while testing your script.

    The GetAbsolutePathName method will return a text string containing a full file path.  If a full path is not supplied to it, it will create one by assuming the partial path is relative to the script’s execution directory.  Here’s what that means.

    If we supply only a filename, it will assume the file resides in the same directory as our script and return a full path to that file.  If we supply something like “includesmyinclude.vbs”, it will assume that the “includes” directory resides in the same directory as our script and return a full path accordingly.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · 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 4 hosted by Hostway