Dear John, How Do I... Use Named Arguments?

The most common way to pass arguments in Visual Basic, and indeed in almost every programming language, is by position in a comma-delimited list. So, for instance, if you create a procedure that expects the parameters (sngRed, sngGreen, sngBlue), you always pass three values to the procedure and it's understood that the first argument will always represent sngRed, the second sngGreen, and the last sngBlue.

Now take a look at the following procedure and the code that calls it. Here I've used explicit parameter names to pass the three arguments, but in reverse order!

Option Explicit

Private Sub FormColor(sngRed As Single, sngGreen As Single, _ 
    sngBlue As Single)
    BackColor = RGB(sngRed * 256, sngGreen * 256, sngBlue * 256)
End Sub 

Private Sub Form_Click()
    FormColor sngBlue:=0, sngGreen:=0.5, sngRed:=1    `Brown
End Sub

The real value of named arguments lies not so much in their ability to be passed in any order as in their ability to clearly pass a subset of parameters to a procedure that expects any of a large number of parameters. To take full advantage of named arguments in your applications, you need to make some or all of your parameters optional, which takes us right into the next question.