Featured Programming

VBScript: Include Function

Another interesting VBScript Function I created in the past for larger scripting projects. This will give you the ability to “outsource” code from your main script file. This function is known and built into other languages such as C++, .NET, PHP, etc. for years.

PHP-Include Reference: http://php.net/manual/de/function.include.php
(functionality is pretty much the same in my VBScript function)

' #####################################################################
' ##
' ## (C) 2011 Michael Miklis (michaelmiklis.de)
' ##
' ## 
' ## Filename:      Include.vbs
' ##
' ## Version:	    1.0
' ##
' ## Release:	    Final 
' ##
' ## Requirements:  -none-
' ## 
' ## Description:   Include function for external Code-Files
' ##
' ## This script is provided 'AS-IS'.  The author does not provide 
' ## any guarantee or warranty, stated or implied.  Use at your own 
' ## risk. You are free to reproduce, copy & modify the code, but 
' ## please give the author credit. 
' ##
' ####################################################################
Option Explicit

Include("C:code.inc.vbs")

'______________________FUNCTIONS & SUB ROUTINES_______________________

Sub Include(strFilename)
	'// <summary> 
	'// Include function for C-Style include from
	'// external script files
	'// </summary>
	'// <param name="strFilename">external code file</param> 
	Dim objFSO, objHANDLE


	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objHANDLE = objFSO.OpenTextFile(strFilename)

	ExecuteGlobal objHANDLE.ReadAll
	objHANDLE.Close()

	Set objHANDLE = Nothing
	Set objFSO = Nothing
End Sub


You may also like
Changing a Template or Templatepath in Word Documents via Script
Netatmo Weather Station Shell Script
SCCM 2012 Extension: Remove a Computer from all Collections