This documentation is archived and is not being maintained.

Procedure Declaration Changes in Visual Basic

Visual Basic .NET introduces several changes related to the declaration of procedures.

Optional Arguments

Visual Basic 6.0

In Visual Basic 6.0, you can declare a procedure argument as Optional without specifying a default value. If an optional argument is of the Variant type, the procedure code can use the IsMissing function to determine whether the argument is present.

Visual Basic .NET

In Visual Basic .NET, every optional argument must declare a default value, which is passed to the procedure if the calling program does not supply that argument. The IsMissing function is not needed to detect a missing argument, and it is not supported. The following example shows an optional argument declaration:

Sub Calculate(Optional ByVal Switch As Boolean = False) 

Static Local Variables

Visual Basic 6.0

In Visual Basic 6.0, you can declare a procedure with the Static modifier. This causes every local variable within the procedure to be static and to retain its value between calls.

Visual Basic .NET

In Visual Basic .NET, the Static keyword is not supported in a Function or Sub statement. You must individually declare each local variable you want to be Static.

See Also

Procedure Calling Sequence Changes in Visual Basic | Parameter Passing Mechanism Changes in Visual Basic | Optional | Static | Programming Element Support Changes Summary