After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Using "Include" files in VBScript Without Using ASP

Author Message
DiGiTAL.SkReAM
  • Total Posts : 1259
  • Scores: 7
  • Reward points : 0
  • Joined: 9/7/2005
  • Location: Clearwater, FL, USA
Using "Include" files in VBScript Without Using ASP - Thursday, January 12, 2006 8:47 AM
0
I searched, and didn't find anything else on this topic, so figured I'd post.  If someone else has done this before, I am reasonably certain that some folks will take great pleasure in pointing it out to me.
To use an include file in a vbscript, without have to reference it via ASP/HTA/html tags, etc. do the following:
The 'include' file can contain any normal vbscript, etc. that you would have in any other .vbs file, including subs and functions.
 
To access the code,
 
set oFile = fso.OpenTextFile(sFileName,1)
sText = oFile.ReadAll
oFile.close
ExecuteGlobal sText
 
And voila, the commands that you had in the include file are ran.
 
 
"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

ebgreen
  • Total Posts : 8081
  • Scores: 94
  • Reward points : 0
  • Joined: 7/12/2005
RE: Using "Include" files in VBScript Without Using ASP - Thursday, January 12, 2006 8:50 AM
0
There is a function here that will do this with some error checking:
http://www.visualbasicscript.com/m_29285/tm.htm
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

Fredledingue
  • Total Posts : 572
  • Scores: 0
  • Reward points : 0
  • Joined: 5/9/2005
  • Location: Europe
RE: Using "Include" files in VBScript Without Using ASP - Saturday, January 14, 2006 8:06 AM
0
It can be useful for codes that are shared by a large number of vbs.
 
I often use this method to pass parameters. I have in my file for example:
 
x=1
y=2
z=3
string = "my string"
 
...
 
Then I open this file for reading and do  "Execute oFile.readAll".
 
What's the difference between "Execute" and "ExecuteGlobal"?
 
 
 
Fred

ehvbs
  • Total Posts : 3310
  • Scores: 110
  • Reward points : 0
  • Joined: 6/22/2005
  • Location: Germany
RE: Using "Include" files in VBScript Without Using ASP - Saturday, January 14, 2006 8:21 AM
0
Hi Fredledingue,

ExecuteGlobal:
   Executes one or more specified statements in the global namespace of a script.


Execute:

   Executes one or more specified statements.

This explanation straight from the VBScript Docs doesn't explicitly say what "non
global" means, but they provide an example showing it by code.

If you use your "Execute oFile.readAll" in a sub or function you can get at
x, y, z in this sub/function only (the execution is local to the sub/function).
By using ExecuteGlobal (even in a sub/function) you add your variables (and
possibly subs/functions/classes from you file) to the global namespace of
your script.



TNO
  • Total Posts : 2089
  • Scores: 34
  • Reward points : 0
  • Joined: 12/18/2004
  • Location: Earth
RE: Using "Include" files in VBScript Without Using ASP - Wednesday, March 19, 2008 11:16 AM
0
I think this was one of the reasons why script components were invented. Just too bad this is IE only technology.
To iterate is human, to recurse divine. -- L. Peter Deutsch

DiGiTAL.SkReAM
  • Total Posts : 1259
  • Scores: 7
  • Reward points : 0
  • Joined: 9/7/2005
  • Location: Clearwater, FL, USA
RE: Using "Include" files in VBScript Without Using ASP - Wednesday, March 19, 2008 12:26 PM
0
When you say 'too bad this is IE only technology', what exactly are you referring to?
 
"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

TNO
  • Total Posts : 2089
  • Scores: 34
  • Reward points : 0
  • Joined: 12/18/2004
  • Location: Earth
RE: Using "Include" files in VBScript Without Using ASP - Wednesday, March 19, 2008 12:41 PM
0
Creating a Windows Script component as you know, turns your script into a COM component basically. So,


Dim TNO
Set TNO = CreateObject("TNO.Framework");


Can be used in the browser, HTML Application and on an ASP page as Server.CreateObject("TNO.Framework")

When I say this is IE only, I mean if I used the above in my webpage using JavaScript:

var TNO = new ActiveXObject("TNO.Framework");


I don't expect Opera, Safari, FireFox, etc to execute it, forcing me to create a separate library.

But, I may have spoken too soon, I haven't tested this yet, but perhaps by using the <object> tag instead and/or GeckoActiveXObject() would still allow sharing the same file across client/server. But of course I have no idea if a .wsc can be used in this manner (not using activeXObject/CreateObject)
To iterate is human, to recurse divine. -- L. Peter Deutsch

DiGiTAL.SkReAM
  • Total Posts : 1259
  • Scores: 7
  • Reward points : 0
  • Joined: 9/7/2005
  • Location: Clearwater, FL, USA
RE: Using "Include" files in VBScript Without Using ASP - Wednesday, March 19, 2008 10:23 PM
0
Actually, I didn't know. hehehe  I work pretty exclusively in vanilla vbscript.  .WSC, etc. are just random groupings of letters used to form arcane and mysterious filename externsions to me.
When i want to get REALLY crazy and wild, I write a .HTA.
 
I thought you were referring to the ExecuteGlobal and Execute commands.
"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

TNO
  • Total Posts : 2089
  • Scores: 34
  • Reward points : 0
  • Joined: 12/18/2004
  • Location: Earth
RE: Using "Include" files in VBScript Without Using ASP - Tuesday, May 12, 2009 7:37 AM
0
Another approach which IMO is the best way to do it:

MyFile.wsf
 <job id="Foo">
     <?job debug="true"?>
     <script language="JScript" src="e:/lib/JSON.js"/>
     <script language="VBScript" src="e:/lib/RegList.js"/>
     <script language="VBScript">
         'Do Stuff
     </script>
 </job>
 


Plus as you can see, you can mix languages. Its also possible to have multiple <job> tags with different id's:

 <package>
     <job id="DoneInVBS">
     <?job debug="true"?>
         <script language="VBScript">
            WScript.Echo "This is VBScript"
         </script>
     </job>
     <job id="DoneInJS">
     <?job debug="true"?>
         <script language="JScript">
            WScript.Echo("This is JScript"); 
         </script>
     </job>
 </package>


This gives you the added power to execute each piece individually from the command line:

cscript myScript.wsf //job:DoneInJS
cscript myScript.wsf //job:DoneInVBS
To iterate is human, to recurse divine. -- L. Peter Deutsch

bbotts77
  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 6/30/2009
RE: Using "Include" files in VBScript Without Using ASP - Tuesday, June 30, 2009 3:40 AM
0


<package>
    <job id="DoneInVBS">
    <?job debug="true"?>
        <script language="VBScript">
           WScript.Echo "This is VBScript"
        </script>
    </job>
    <job id="DoneInJS">
    <?job debug="true"?>
        <script language="JScript">
           WScript.Echo("This is JScript"); 
        </script>
    </job>
 </package>
 



I don't consider myself a noob to VBScript, but I've never seen <package> or <job> tags. Are these browser or interpreter specific? Where can I get more info on how to use these tags?

Thanks,
Ben

ebgreen
  • Total Posts : 8081
  • Scores: 94
  • Reward points : 0
  • Joined: 7/12/2005
RE: Using "Include" files in VBScript Without Using ASP - Tuesday, June 30, 2009 4:13 AM
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

bbotts77
  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 6/30/2009
RE: Using "Include" files in VBScript Without Using ASP - Tuesday, June 30, 2009 4:17 AM
0
Thanks ebgreen. I just stumbled across it somewhere else a couple of minutes ago. This link should help though.

Thanks again,
Ben


ORIGINAL: ebgreen

It is Windows Script Components http://msdn.microsoft.com/en-us/library/07zhfkh8(VS.85).aspx