Categories
Archives
Authors
 
06

.:.

Considering that we already have available a method to perform includes in vbscript as we explained in our article on Using Includes in vbscript it is easy to imagine a scenario where all of our classes or scripts are stored in one place and that through an instruction or command include can load and use. In short to have a Vbscript Classes Repository with the benefits of code reuse and we can use in a logical and organized manner. To achieve this goal we must generate a series of conventions that provide instructions or pattern and define their use, and which we propose the following:

  • Every new script vbscript is created from the template IncludeTemplate.vbs (See article here) to get:
    • Ability to include code in your scripts through the Include clause.
    • The collection IncludeFilesList used by the template avoids the inclusion of more than once a file or class code, this allows you to run recursive include without any problem because the code will be included only once.
    • The variable RepositoryFolderPath sets the standard directory path where we have to store all of our code files and classes. With this definition we only need to reference the files by name only because the subroutine Include will search first in the directory path.
  • Is defined as a principle that every code file or class definition must be stored in the directory path defined for the classes repository.
  • Any code that we think can be recycled, should be defined as a class with their properties and methods.
  • The name of the file containing the definition of a class must equal the name of the class adding the extension .class this allows to easily find file include knowing the name of the class that we use in our script, that is: File Name = Class Name + .class.
  • In the definition of a class can do Include in the header to other classes follow the same structure as explained above, this is valid because there is only one routine Include and is written in the original script and it controls to be including. In a few words in the definition of a classes there will be no routine Include and every time you make an include will be used routine Include in our script.

Finally we see some examples of how to execute the Include It also shows that file is searched and loaded from the repository on each call.

Include Samples
Class Name
Source Code
Name of the file to upload
ObjectManager
Dim objManager
RepositoryFolderPath="\\FileServer\MyRepository"
Include "ObjectManager.class"
Set ObjManager = New ObjectManager
            
ObjectManager.class
DateTime
Dim BirthDate
RepositoryFolderPath="\\FileServer\MyRepository"
Include "DateTime.class"
Set BirthDate = New DateTime
            
DateTime.class
ActiveDirectory
Dim ObjActiveDirectory
RepositoryFolderPath="\\FileServer\MyRepository"
Include "ActiveDirectory.class"
Set ObjActiveDirectory = New ActiveDirectory
ActiveDirectory.class

 

The scripts we will write in future articles will be based on this philosophy that we explain here and it will be our standard for the development of scripts, I hope that the explanation was clear and I appreciate your comments and suggestions for improvement.

We apologize for any errors in the syntax and semantics of the articles in the English version, these were done with our current knowledge of the English language and with the support of the site http://translate.google.com.


Posted in: VbScript

Comentarios

Actualmente no hay comentarios, sera el primero en publicar uno.

Digite su comentario

Name (required)

Email (required)

Website

Enter the code shown above:

 
Inspired by Nina