Defining arguments

Like built-in functions, user-defined functions can have any number of arguments, including none. You declare the arguments and their types when you define a function.

Passing arguments

In user-defined functions, you can pass arguments by reference, by value, or read-only. You specify this for each argument in the Pass By list.

By reference When you pass an argument by reference, the function has access to the original argument and can change it directly.

By value When you pass by value, you are passing the function a temporary local copy of the argument. The function can alter the value of the local copy within the function, but the value of the argument is not changed in the calling script or function.

Read-only When you pass as read-only, the variable’s value is available to the function but it is treated as a constant. Read-only provides a performance advantage over passing by value for string, blob, date, time, and datetime arguments, because it does not create a copy of the data.

NoteIf the function takes no arguments Leave the initial argument shown in the Prototype window blank.

StepsTo define arguments:

  1. Declare whether the first argument is passed by reference, by value, or read-only.

    The order in which you specify arguments here is the order you use when calling the function.

  2. Declare the argument’s type. You can specify any datatype, including:

    • Built-in datatypes, such as integer and real

    • Object types, such as window, or specific objects, such as w_emp

    • User objects

    • Controls, such as CommandButtons

  3. Name the argument.

  4. If you want to add another argument, press the Tab key or select Add Parameter from the pop-up menu and repeat steps 1 to 3.

NotePassing arrays You must include the square brackets in the array definition, for example, price[ ]or price[50], and the datatype of the array must be the datatype of the argument. For information on arrays, see the PowerScript Reference.