13.8. Use Optional Parameters

Problem

You need to call a method in a COM component without supplying all the required parameters.

Solution

Use the Type.Missing field.

How It Works

The .NET Framework is designed with a heavy use of method overloading. Most methods are overloaded several times so that you can call the version that requires only the parameters you choose to supply. COM, on the other hand, does not support method overloading. Instead, COM components usually use methods with a long list of optional parameters. You do not need to specify values for the optional parameters. For example, if a method includes three optional parameters, you can assign a value to the first and third one, skipping the second one. Passing Nothing to the ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.