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
  • Status: offline
Using "Include" files in VBScript Without Using ASP Thursday, January 12, 2006 8:47 AM (permalink)
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
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: Using "Include" files in VBScript Without Using ASP Thursday, January 12, 2006 8:50 AM (permalink)
    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
     
    #2
      Fredledingue

      • Total Posts : 572
      • Scores: 2
      • Reward points : 0
      • Joined: 5/9/2005
      • Location: Europe
      • Status: offline
      RE: Using "Include" files in VBScript Without Using ASP Saturday, January 14, 2006 8:06 AM (permalink)
      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
       
      #3
        ehvbs

        • Total Posts : 3321
        • Scores: 110
        • Reward points : 0
        • Joined: 6/22/2005
        • Location: Germany
        • Status: offline
        RE: Using "Include" files in VBScript Without Using ASP Saturday, January 14, 2006 8:21 AM (permalink)
        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.


         
        #4
          TNO

          • Total Posts : 2094
          • Scores: 36
          • Reward points : 0
          • Joined: 12/18/2004
          • Location: Earth
          • Status: offline
          RE: Using "Include" files in VBScript Without Using ASP Wednesday, March 19, 2008 11:16 AM (permalink)
          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
           
          #5
            DiGiTAL.SkReAM

            • Total Posts : 1259
            • Scores: 7
            • Reward points : 0
            • Joined: 9/7/2005
            • Location: Clearwater, FL, USA
            • Status: offline
            RE: Using "Include" files in VBScript Without Using ASP Wednesday, March 19, 2008 12:26 PM (permalink)
            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
             
            #6
              TNO

              • Total Posts : 2094
              • Scores: 36
              • Reward points : 0
              • Joined: 12/18/2004
              • Location: Earth
              • Status: offline
              RE: Using "Include" files in VBScript Without Using ASP Wednesday, March 19, 2008 12:41 PM (permalink)
              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
               
              #7
                DiGiTAL.SkReAM

                • Total Posts : 1259
                • Scores: 7
                • Reward points : 0
                • Joined: 9/7/2005
                • Location: Clearwater, FL, USA
                • Status: offline
                RE: Using "Include" files in VBScript Without Using ASP Wednesday, March 19, 2008 10:23 PM (permalink)
                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
                 
                #8
                  TNO

                  • Total Posts : 2094
                  • Scores: 36
                  • Reward points : 0
                  • Joined: 12/18/2004
                  • Location: Earth
                  • Status: offline
                  RE: Using "Include" files in VBScript Without Using ASP Tuesday, May 12, 2009 7:37 AM (permalink)
                  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
                   
                  #9
                    bbotts77

                    • Total Posts : 2
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 6/30/2009
                    • Status: offline
                    RE: Using "Include" files in VBScript Without Using ASP Tuesday, June 30, 2009 3:40 AM (permalink)
                    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
                     
                    #10
                      ebgreen

                      • Total Posts : 8227
                      • Scores: 98
                      • Reward points : 0
                      • Joined: 7/12/2005
                      • Status: offline
                      RE: Using "Include" files in VBScript Without Using ASP Tuesday, June 30, 2009 4:13 AM (permalink)
                      "... 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
                       
                      #11
                        bbotts77

                        • Total Posts : 2
                        • Scores: 0
                        • Reward points : 0
                        • Joined: 6/30/2009
                        • Status: offline
                        RE: Using "Include" files in VBScript Without Using ASP Tuesday, June 30, 2009 4:17 AM (permalink)
                        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
                         
                        #12

                          Online Bookmarks Sharing: Share/Bookmark

                          Jump to:

                          Current active users

                          There are 0 members and 1 guests.

                          Icon Legend and Permission

                          • 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
                          • Read Message
                          • Post New Thread
                          • Reply to message
                          • Post New Poll
                          • Submit Vote
                          • Post reward post
                          • Delete my own posts
                          • Delete my own threads
                          • Rate post

                          2000-2012 ASPPlayground.NET Forum Version 3.9