A function is a named piece of code executed as a unit. It can receive several values (arguments) and return some value. For example, function win receives window name and several other properties, finds the window and returns window handle. Beside predefined functions (QM intrinsic functions, dll and COM functions), you can create your own (user-defined) functions. Usually, you create a function when you want to have a piece of code that can be executed more than once, in any macro. Instead of placing the same code in each macro, you place it in a function, and then call the function by name from any macro.
Global functions (intrinsic, user-defined and dll functions) are called using syntax
func([a b ...])
Here func is function name; a, b and c are arguments.
If function's return value is not used, parentheses are optional. Function's return value can be assigned to a variable. Or, function can be an argument of another function or part of an expression with operators. Examples:
Func a b variable = Func(a b) Func2(a Func(b c)) d = e + Func(b c) / 10
Member functions of str, OLE types, user-defined types and COM interfaces are called using syntax
var.Func([a b ...])
Here var is variable for which is called function Func. Type of var is type to which is assigned function Func. For example, to use str functions, you declare str variable:
str s s.format("%i %i" a b)
User-defined and dll functions also can be called by address.
are listed in Reference topic. In code, they have blue color.
An user-defined function is a macro that can be called from other macros. In code, user-defined functions are sky blue.
See also: Function tips
To define function's type and arguments, use function statement. To return a value, use ret statement. You can get function address with & operator, and this allows you to use functions as callback functions. You can also start an user-defined function like a macro (not from code). Functions can be recursive (call itself, directly or through other function). Every running function instance has its own local variables.
Below is shown how function is called and executed. Red lines - execution flow direction. Green lines - passing and returning values. The second argument is declared as reference (&), therefore the function receives address of variable e and can modify its value.

User-defined member functions are assigned to types. They are similar to simple user-defined functions, but can be called only with a variable of that type. No other way exists to execute member function.
You can use any dll functions (Windows API, C run-time library and other) in QM macros. To declare a dll function, use the dll statement. For information about a dll function, press F1 and search in the MSDN library or Internet.
You also can use COM functions.