function ... end function 

ユーザー定義のファンクションを作成する。 ファンクションとはプログラムのなかで何度も使われるインストラクションのシークエンスである。

書式:
function name ( parmlist {...} )
    shared variable {, ..}
    dim variable {, ...}
    commands
    {exit function}
    {return function}
    { functionName = expression }
end function

name サブルーチンの名前,最初が数字以外の英文字で始まる文字列。 たとえば: 1printString は正しくない。printString1 は正しい。
args ファンクションに引き渡す変数等のアーギュメント。 represent the variables used to pass argument to the function.
{,...} はファンクションが不規則な数のアーギュメント を引き渡すことができるということ。

ファンクションのなかで使用される変数はローカル変数である。 ということはメインプログラムのなかで同じ名前の変数が使用されていても他の変数へは影響しない。 Variables used inside the function are local variables, that means they will not influence other variables that happens to use the same variable name in your main program or in any other function. This is valid for arrays too. See common statements for more details.
You can pass to the function a list of parameters containing the informations to be processed from the function itself. Functions that do not require input parameters can be called from your main program without using brackets.
Functions can optionally return values,specified by the return statement. Returning values can be ignored by the calling instruction, in this case functions behave like subroutines.

書式:
function myFunction(a,b)
    return a*b
end function
print myFunction(10,4)
print myFunction(3,5)
print myFunction(7,8)

You can mix required with optional args. The total number of arguments can be found by calling function argument() , and the function argument(n) returns a particular argument passed to the caller.


例:
' sum the args passed
function sumNumbers( a )
    total = 0
    for i = 1 to argument()    
        total = total + argument( i )
    end for
    return sum
end function

参照: shared , dim , exit function , return