Function Reference


Call

Calls a user-defined function contained in a string parameter.

Call ( "function" [, param1 [, param2 [, paramN]]] )

Parameters

function The name of the user function to call.
param Arguments that will be passed to the function being invoked.

Return Value

Success: Returns the return value of the called function. Both @error and @extended may contain values if the called function set them.
Failure: Sets @error to 0xDEAD and @extended to 0xBEEF if the function does not exist or invalid number of parameters.

Remarks

The function cannot be a built-in AutoIt function or plug-in function.
The function can pass arguments to functions, however, ByRef parameters are not supported; there is no way to retrieve the ByRef parameter.
A special array can be passed in lieu of individual parameters. This array must have its first element set to "CallArgArray" and elements 1 - n will be passed as seperate arguments to the function. If using this special array, no other arguments can be passed to Call(). See example for a demonstration.
Both Call() itself can set @error or the called function can set @error. If Call() sets @error the value will be 0xDEAD and @extended will also be set to 0xBEEF. See the example for a demonstration of testing for a function that was not found.

Related

Execute

Example


; This calls a function accepting no arguments.
Call("Test1")

; This calls a function accepting one argument and passes it an argument.
Call("Test2", "Message from Call()!")

; This demonstrates how to use the special array argument.
Global $aArgs[4]
$aArgs[0] = "CallArgArray" ; This is required, otherwise, Call() will not recognize the array as containing arguments
$aArgs[1] = "This is a string" ; Parameter one is a string
$aArgs[2] = 47 ; Parameter two is a number
Global $array[2]
$array[0] = "Array Element 0"
$array[1] = "Array Element 1"
$aArgs[3] = $array ; Parameter three is an array

; We've built the special array, now call the function
Call("Test3", $aArgs)

; Test calling a function that does not exist.  This shows the proper way to test by
; checking that both @error and @extended contain the documented failure values.
Local Const $sFunction = "DoesNotExist"
Call($sFunction)
If @error = 0xDEAD And @extended = 0xBEEF Then MsgBox(4096, "", "Function does not exist.")

Func Test1()
    MsgBox(4096, "", "Hello")
EndFunc   ;==>Test1

Func Test2($sMsg)
    MsgBox(4096, "", $sMsg)
EndFunc   ;==>Test2

Func Test3($sString, $nNumber, $aArray)
    MsgBox(4096, "", "The string is: " & @CRLF & $sString)
    MsgBox(4096, "", "The number is: " & @CRLF & $nNumber)
    For $i = 0 To UBound($aArray) - 1
        MsgBox(4096, "", "Array[" & $i & "] contains:" & @CRLF & $aArray[$i])
    Next
EndFunc   ;==>Test3