Named Parameters (topic)

Many language elements in BasicScript support named parameters. Named parameters allow you to specify parameters to a function or subroutine by name rather than in adherence to a predetermined order. The following table contains examples showing various calls to MsgBox both using parameter by both name and position.

By Name

MsgBox Prompt:="Hello, world."

By Position

MsgBox "Hello, world."

By Name

MsgBox Title:="Title", Prompt:="Hello, world."

By Position

MsgBox "Hello, world",,"Title"

By Name

MsgBox HelpFile:="BASIC.HLP", _


Prompt:="Hello, world.", HelpContext:=10

By Position

MsgBox "Hello, world.",,,"BASIC.HLP",10

Using named parameter makes your code easier to read, while at the same time removes you from knowing the order of parameter. With function that require many parameters, most of which are optional (such as MsgBox), code becomes significantly easier to write and maintain.

When supported, the names of the named parameter appear in the description of that language element.

When using named parameter, you must observe the following rules:

Named parameter must use the parameter name as specified in the description of that language element. Unrecognized parameter names cause compiler errors.

All parameters, whether named or positional, are separated by commas.

The parameter name and its associated value are separated with :=

If one parameter is named, then all subsequent parameter must also be named as shown below:

MsgBox "Hello, world", Title:="Title"    'OK

MsgBox Prompt:="Hello, world.",,"Title"  'WRONG!!!

More information