␡
- The Class Hierarchy
- Creating a New Class
- Declaration and Instantiation
- Constructors and Destructors
- Garbage Collection
- Inheritance
- Object Operators
- Adding and Overriding Methods
- Calling the Overridden Method
- Overloading
- Casting
- Oddities
- Encapsulation
- Access Scope: Public, Private, Protected
- Setting Properties with Methods
- Default and Optional Parameters
- Declaring Variables Static and Const
- Revisiting the StringParser Module
- Example: Creating a Properties Class
- Data-Oriented Classes and Visual Basic Data Types
- Advanced Techniques
This chapter is from the book
Default and Optional Parameters
Optional parameters are really just shortcuts to overloading methods. There are two ways to indicate that a parameter is optional. The obvious way is to use the Optional keyword, like so:
aMethod(aString as String, Optional anInteger as Integer)
The second way is to establish a default value for one of the parameters. Another way to accomplish what I just did in the previous example is this:
aMethod(aString as String, anInteger as Integer = 100)
Really, the Optional keyword just sets a default value of "0" to the anInteger variable, so the only real difference is that you get to set an arbitrary default value when using the second approach.