Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Using "Include" files in VBScript Without Using ASP

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,29820
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Using "Include" files in VBScript Without Using ASP
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Using "Include" files in VBScript Without Usi... - 1/12/2006 7:47:03 AM   
  DiGiTAL.SkReAM


Posts: 1056
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
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.



_____________________________

"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers

"Would you like to touch my monkey?" - Dieter (Mike Meyers)
 
 
Post #: 1
 
 RE: Using "Include" files in VBScript Without... - 1/12/2006 7:50:46 AM   
  ebgreen


Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
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

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 2
 
 RE: Using "Include" files in VBScript Without... - 1/14/2006 7:06:10 AM   
  Fredledingue


Posts: 297
Score: 0
Joined: 5/9/2005
From:
Status: offline
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

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Using "Include" files in VBScript Without... - 1/14/2006 7:21:34 AM   
  ehvbs

 

Posts: 1843
Score: 46
Joined: 6/22/2005
From: Germany
Status: offline
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.

(in reply to Fredledingue)
 
 
Post #: 4
 
 RE: Using "Include" files in VBScript Without... - 3/19/2008 10:16:16 AM   
  TNO


Posts: 974
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
I think this was one of the reasons why script components were invented. Just too bad this is IE only technology.

_____________________________

Consolidated Script Component: Now in Testing stage!

A universe of complexity...

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Using "Include" files in VBScript Without... - 3/19/2008 11:26:44 AM   
  DiGiTAL.SkReAM


Posts: 1056
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
When you say 'too bad this is IE only technology', what exactly are you referring to?


_____________________________

"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

(in reply to TNO)
 
 
Post #: 6
 
 RE: Using "Include" files in VBScript Without... - 3/19/2008 11:41:00 AM   
  TNO


Posts: 974
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
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)

_____________________________

Consolidated Script Component: Now in Testing stage!

A universe of complexity...

(in reply to DiGiTAL.SkReAM)
 
 
Revisions: 1 | Post #: 7
 
 RE: Using "Include" files in VBScript Without... - 3/19/2008 9:23:08 PM   
  DiGiTAL.SkReAM


Posts: 1056
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
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.

_____________________________

"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

(in reply to TNO)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Using "Include" files in VBScript Without Using ASP Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts