Using Optional Parameters in VBScript


One of the nicest features of VisualBasic that is not supported in VBScript is the use of optional arguments to a subroutine or function. In fact, optional arguments are pretty standard in most high-level programming languages... so why aren't they available in VBScript? I can't answer the why, but I can propose a workaround.

If you're a regular 4Guys visitor like myself, you're likely aware that there are already a number of articles that discuss how to simulate optional arguments in VBScript. In the article Optional Arguments in VBScript, author Francis Chau looks at two common methods to simulate optional arguments: an array based approach and a NULL value approach. In the array based approach, rather than having N arguments passed into a subroutine, the developer passes one argument - namely an array containing the values for the specified parameters. In the NULL value approach, specified values are passed into the subroutine while NULL values are passed in for the non-specified values.

You might also like...



Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - Rick Osborne