
This isn't a VillainousMind project, but it is a project I am working on for another group. The idea is to use VB Script (the tech is pretty locked in) to do some work on migration of several applications.
The problem is the majority of the code is in a "common.vbs" file and only the app specific stuff needs to go in an app file. VBScript does not have an include method so one has to be created. There is a lot of stuff out there that is good, but as it requires the calling file to implement a solution each time, the code cannot be placed in the common.vbs. As such, since every app-specific script will require this method, concise code is the main concern.
For brevity, I knocked all the source I found down to a method in one, painful line:
Private Sub IncludeFile (filename)
ExecuteGlobal fso.OpenTextFile(fso.BuildPath( _ fso.GetParentFolderName(WScript.ScriptFullName), _
filename), 1).ReadAll() '1 = ForReading.
End Sub
This requires a global variable (most processes in the common.vbs will want to use this variable so I made it global)
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Finally, to include a file, just call this line:
IncludeFile("common.vbs")
It's ugly, but using VBScript in 2009 is ugly too. This way everything is succinct and easy to use.

0 comments:
Post a Comment