Overloading Methods and More in VBScript
(Page 1 of 4 )
Many programming languages, such as Java or C, allow you to create overloaded methods and allow optional parameters for your methods. This ability has been removed from VB’s Scripting Edition; however, today I’m going to show you some coding techniques that will allow you to regain some of this functionality.
To begin, let’s define what an overloaded method (constructor) really is. Quite simply, overloading is the process of creating multiple instances of a method or function with the same name that accept different inputs and offer different outputs. Programming languages that adhere to strict data types employ overloading to allow similar functions to work on different data types.
public double square(double number)
{
return number * number;
}
public float square(float number)
{
return number * number;
}
In Java, for example, a constructor (basically, a function) is defined by its input and output types as well as its name. So let’s assume you wanted to write a function that would output the square of a number. It might accept a double type as an input, so naturally it would also output a double. You might also want to create the same function again to work with floating point numbers. This second instance would be the overloaded constructor.
This, of course, isn’t possible in VBScript because function and subroutine names must be unique. I suppose constructor overloading wasn’t deemed necessary since all variables in VBS are of type Variant anyway.
Next: Information Overload >>
More Windows Scripting Articles
More By Nilpo