Microsoft KB Archive/163229

= HOWTO: Use Optional Arguments in Intrinsic Data Types =

Article ID: 163229

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q163229



SUMMARY
One of the new features of Microsoft Visual Basic 5.0 and VBA 5.0 is the ability to define Optional arguments for data types other than Variant. These optional arguments are used in procedures.



MORE INFORMATION
Microsoft Visual Basic and VBA 5.0 allows optional arguments for the following data types:

Data type
Currency

Double

Integer

Long

Single

String

Object

The following conditions and notes should be considered:  The Optional argument must be capable of being assigned a default value. When a procedure that has Optional arguments is called, Microsoft Visual Basic 5.0 assigns all arguments that were not included with a default value. Therefore, an Optional array is not possible. Optional arguments of user-defined data types are not supported. Microsoft Visual Basic 5.0 only supports Optional arguments of intrinsic data types.  Optional arguments that are of intrinsic data types always return False when used with the IsMissing function. This occurs because the IsMissing function is explicitly designed for un-initialized Variant data types. Because an intrinsic Optional argument always gets its default value if  not passed to the procedure, it is never missing.  Applications written with earlier versions of Visual Basic for Applications will ignore the Optional modifier, and therefore require the argument(s). A good example of this is Microsoft Access for Windows 95.

