Call Statement
Calls a user function.
Syntax
Call funcName [(argList)]
Parameters
- funcName
- Specify the name of a function to be called.
- argList
- Optional. List of arguments that were specified in the Function declaration. For the argument, use the following syntax: [ByRef] varName [( )], or numerical expression
- ByRef
- Specify ByRef to refer to a variable of the function to be called. In this case, the argument change in a function can be reflected to the variable of the calling side. You can change the values received as a reference.
Description
The Call instruction causes the transfer of program control to a function (defined in Function...Fend). This means that the Call instruction causes program execution to leave the current function and transfer to the function specified by Call. Program execution then continues in that function until an Exit Function or Fend instruction is reached. Control is then passed back to the original calling function at the next statement after the Call instruction.
You may omit the Call keyword and argument parentheses. For example, here is a call statement used with or without the Call keyword:
Call MyFunc(1, 2)
MyFunc 1, 2
You can call an external function in a dynamic link library (DLL). For details, refer to Declare Statement.
To execute a subroutine within a function, use GoSub...Return.
You can specify a variable as an argument. Specifying the ByRef parameter, you can reflect the change of argument in the function to the variable of the calling side.
When specifying the ByRef parameter, you need to specify ByRef as well for the argument list of the function definition (Function statement) and DLL function definition (Declare statement).
ByRef is necessary when giving an array variable as an argument.
See Also
Function, GoSub
Call Statement Example
[File1: MAIN.PRG]
Function main
Call InitRobot
Fend
[File2: INIT.PRG]
Function InitRobot
If Motor = Off Then
Motor On
EndIf
Power High
Speed 50
Accel 75, 75
Fend