Optional Parameters

VB.NET allows parameters to be defined as optional. That is, the calling statement may or may not pass a value for that parameter. If optional parameters are defined, a default value for them must be specified. When arguments are passed, the actual argument is used. When no argument is passed, the default value for the parameter is used.

To define a parameter as optional, the keyword Optional is used. The default value for the parameter is specified using the assignment operator and a value after the declaration. The example OptionalParameters illustrates the use of these parameters.

 ' Calculates shipping costs; assumes that the Rapid Express ' is the default shipper. Shipper codes are: ' 1=Rapid Express, 2=Quick Shippers, ...

Get Application Development Using Visual Basic® and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.