

The variable that is returned by a function can be a “regular” single-element variable or an array. See the Sub statement for more information. A Sub is a method that does not return a value. If your method does not need to return a value, you declare it as a Sub. See the RuntimeExceptionclass and the Try and Exception statements for more information. If the Return statement is not called, the default value of the data type returned by the function is returned (Nil for objects).Įxception handlers are statements that handle errors. The Return statement can be used to immediately return control to the statement that called the function and to pass back a value to the left side of the statement. A Var statement can be placed anywhere within the function. They are created by using the Var statement from within a Sub or function. Consequently, they can only be accessed by the statements within the function. Local variables are variables that are created each time the function is run and destroyed when the function finishes. Properties can be accessed from within any Sub or function. Variables and parameters used in a function are local.

When you declare parameters, you declare the name of each parameter and its data type in the form:Īll variables used in a function must be declared before they are used in a statement. You call a function by using its name followed by its parameters in parentheses.
#On error in xojo code
Once the last line of code is executed, control returns to the line that called the function. A function executes each line of code from the top down. A function cannot be defined inside another Sub or function. A Function differs from a Sub in that a Function can be used on the right side of an expression and a Sub cannot. All executable code must be in a Sub or Function statement. The Function statement is used to define a method that can be used on the right side of an expression just like the built-in functions such as Abs, Len, etc. The data type of the value returned by the function. The default value can be a literal, a constant, or an enum. You can optionally assign default values to parameters. Multiple parameters are separated by commas. Optional list of values representing parameters that are passed to the function when it is called. The name of the function (method) follows standard variable naming conventions.
