User guide
44
VTB USER GUIDE
10 FUNZIONI
VTB manages functions with the same syntax as VISUAL BASIC. It exist a limitation in the declaration of internal variables:
they can not be ARRAYS, STRUCTURES or BITS.
10.1 Declaration of a function
Syntax
function function_name(par_1 as int, par_2 as char, ….., par_n as *long) as function_type
dim var as int ‘local variables
....
.... ‘body of the function
....
function_name = return_value
endfunction
The syntax of a function is composed by the following elements:
function Mandatory. Keyword identifying the begin of a function.
function_name Mandatory. Unambiguous name of the function chosen by programmer.
par_1...par_n Optional. They are the parameter passed to the function. If no parameter have to be
passed (VOID) there must be nothing inside the parenthesis.
function_type Mandatory. It defines the data type returned from the function. If no data have to be
returned write as void.
local variables Optional. Local variables are allocate at the moment when function is called and
then destroyed when it returns.
They can be of any types except ARRAYS, STRUCTURES or BITS.
body of the function Optional. Block of instruction execute by the function.
function_name=… Optional. It assigns the value returned from the function.
endfunction Mandatory. Keyword to identifying the end of the function.
Notes
A function can be called simply writing its name passing to it the eventual parameters declared.
To return from the function in any moment it can be used the instruction return.
The assignment nome_funzione = …. doesn't cause the return from the function but only the assignment of the return
value.
Example:
Used variables:
result as int
number_a as int
number_b as int
Page Function of Main task (functions declaration):
function int_average(number_1 as int, number_2 as int) as int
dim temp as int
temp=(number_1+number_2)/2
int_average=temp
endfunction
Anywhere in the source code (function calling):
number_a=13
number_b=33
result=int_average(number_a, number_b)