About named arguments

Named arguments provide an alternative to putting arguments in a specific argument. With named arguments, you can just type the argument name followed by a colon and an equal sign ( :=) and the value you want for that argument. For example, the following statement is equivalent to x = MsgBox("Hello World", ,"Howdy"), but it uses argument names rather than commas to specify which argument is receiving which value.

x=MsgBox(prompt:="Hello World", title:="Howdy")

Unfortunately, it's not always easy to tell whether a statement supports named arguments. The Quick Info doesn't provide any clues, and the Help doesn't often show the syntax with the optional names in place. About the only clue you get as to whether a statement supports named arguments is from the sentence above the argument descriptions in Help. For example, refer to the Help for the MsgBox function in Figure 3-4: namely, the sentence The MsgBox function syntax has these names arguments, just below the syntax chart for MsgBox(). But because named arguments are entirely optional, you don't have to worry about accidentally excluding them when writing your own code.

0 0

Post a comment