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.




REALbasic Cross-Platform Application Development
REALbasic Cross-Platform Application Development
ISBN: 0672328135
EAN: 2147483647
Year: 2004
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net