HOWTO: Use Optional Arguments in Intrinsic Data Types (163229)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

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:
  1. 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.
  2. Optional arguments of user-defined data types are not supported. Microsoft Visual Basic 5.0 only supports Optional arguments of intrinsic data types.
  3. 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.
    						
  4. 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.

REFERENCES

Microsoft Visual Basic Online Help

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto KB163229