Function...ExitFunction...EndFunction
Program flow management function.
The Function...EndFunction structure defines a function in order to make scripts more modular.
Syntax
Function <function_name>([<param1>[,<param2>]....])
[Local <variable_name>]
<statements>
...
<function_name>=<value>
...EndFunction
Parameters
<function_name>, name of the function. The maximum length of the name is 32 characters.
<param1>, <param2> optional parameters.
The keyword LOCAL allows the declaration of local variables.
ExitFunction is used to quit the function within the function.
Remarks
NOTE : all functions must be declared at the beginning of the script, just after the DIM statements (if any are needed).
If the function returns a string, its name must end with a $, see the example below.
Parameters cannot be arrays. See below an example code demonstrating how to pass arrays in a function using a global variable.
See also
Example code
Function value_absolute_dif(int1, int2)
if int1 > int2 then
value_absolute_dif = int1 - int2
else
if int1 = int2 then
value_absolute_dif = 0
else
value_absolute_dif = int2 - int1
endif
endif
Endfunction
res = value_absolute_dif(my_number,123)
With a function returning a string:
Function concat$(string1$,string2$)
local result$
result$=string1$+string2$
concat$=result$
EndFunction
'Call example
msgbox(concat$("Hello"," WinTask"))
Example code - use of an array
Dim buffer$(100)
dim k1$(100)
dim k2$(100)
function insert_values(nb_row)
i=0
repeat
setclipboard(buffer$(i))
i=i+1
until i=nb_row
endfunction
'Call the function, but first fill the global variable buffer$ by the data you want.buffer$()=k1$()
insert_values(10)
buffer$()=k2$()
insert_values(30)