Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 - Building the basic routine.


    (Page 2 of 6 )

    To begin, we first need to understand what we’re trying to accomplish.  In essence, we want to read code from one file and execute it from another.  That seems simple enough.  First let’s look at how we can read in code from another file.

    Sub Import(strFile)

       Set objFs = CreateObject("Scripting.FileSystemObject")

       Set objFile = objFs.OpenTextFile(strFile)

       strCode = objFile.ReadAll

       objFile.Close

    End Sub

    What we’ve done here is very simple.  You should be able to recognize this code immediately if you’ve been reading my other articles.  For those who are just tuning in, we’ll go over it very briefly.

    I’ve created a subroutine called Import that accepts a single parameter.  (Hey, I’m a Python fan.  You could easily call this subroutine Include or any other sensible name).  My subroutine first instantiates, or creates and instance of, the VBScript FileSystemObject that we can use to work with the external file.

    Next, it uses the OpenTextFile method to open the file path that was passed to the subroutine.  The OpenTextFile method returns a file object that we’ve assigned to the objFile variable.

    We finish up by using the ReadAll method to return all of the text from our file object, which we assign to a string variable, before closing the file.  See?  I told you it was simple.

    Now that we have the code from our external file it’s time to execute it.

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


       · Everyone loves a good workaround. This one lets you take advantages of code...
       · Thank you so much for posting your code. This is EXACTLY what I was looking for....
       · Thank you so much for you kind words. I'm glad you found this code useful.
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek