Passing Arguments by Position and by Name

When you call a procedure, you usually pass arguments by position — the same sequence given in the declaration of the procedure. But you can also pass them by name, and ignore their positions.

When you pass an argument by name, you give the sequence: (1) its name from the declaration, (2) a colon and an equals sign (:=), and (3) the argument value. Named arguments ignore all position information.

For example, you can pass three arguments to the procedure that follows.

Sub Test ( arg1 As String,
        Optional arg2 As String = "bar",
        arg3 As Int32 = 42 )
    #Debug.PrintLine $"arg1 = ""{arg1}"""
    #Debug.PrintLine $"arg2 = ""{arg2}"""
    #Debug.PrintLine $"arg3 = {arg3}"
End Sub

Arguments passed by position

Call Test "foo", "baz", 3
Call Test "foo", , 3

Arguments passed by name

Call Test arg3 := 3, arg2 := "baz", arg1 := "foo"

Mixed arguments, by position and by name

Call Test "foo", arg3 := 3, arg2 := "baz"

Optional arguments supplied by name


Limits on arguments supplied by name


See also