Sidestepping Arguments

Normally, the calling statement must supply the same number of arguments that the declaration of a function or subroutine specifies. If, however, you want the calling statement to work even if it doesn’t specify a full set of arguments, you can make one or more arguments optional. This requires special coding on the Function or Sub statement and there are two ways to do it. To use the first approach, follow this procedure:

  1. Begin the declaration of each optional argument with the word Optional.

  2. Specify a default value for each optional argument. To do this, add an equal sign and a constant expression to the end of the argument declaration.

  3. Declare all the mandatory arguments first, and then all optional arguments.

In the following ...

Get Faster Smarter Beginning Programming 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.