Knowledge Base

HOWTO: Use Optional Arguments in Intrinsic Data Types

Article ID: 163229

Article Last Modified on 10/11/2006


APPLIES TO


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

Additional query words: simple data types nonvariant kbVBA500 kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport kbVBA

Keywords: kbhowto KB163229