Understanding Procedures in VBScript
(Page 1 of 5 )
In programming, procedures are code structures that contain reusable code. Instead of recreating the series of statements over and over again, you can package your code in a procedure and call that procedure whenever you want that code group to execute. In short, procedures can be used as a way to simplify your code.
Using procedures in your code is a programming technique known as modularizing. Modularized code is easier to read and often easier to work with. Modularizing your code can also aid in debugging by reducing the number of possible error points.
So what types of statements can be modularized into procedures? Well, simply put, any of them. However, procedures should be used to group similar or related statements for a specific purpose or task. Then you can call that procedure anytime that you need to perform the given task without having to recreate each of the steps required.
Take for instance a script that checks your email box for new emails. You first need to connect to the mail server. Then, you need to determine whether or not there are new mails. Finally, you need to return a value that indicates whether or not new mail exists.
Rather than recreating these steps, you could package them in a procedure called CheckNewMail. Then, you could simply call the CheckNewMail procedure any time you wanted to know if new mail existed.
Learning to properly implement procedures is a necessary step as you progress as a programmer. Understanding these procedures is also necessary when using external objects or classes. Now that you have a basic understanding of what procedures are, let’s take a look at the different procedures offered by VBScript and create a few working examples.
Next: Subs and Functions >>
More Windows Scripting Articles
More By Nilpo