Difference between revisions of "MC-Basic:FUNCTION ... END FUNCTION"

From SoftMC-Wiki
Jump to: navigation, search
m
Line 4: Line 4:
  
 
|SYNTAX=
 
|SYNTAX=
Function''<name>''({''{ByVal}<p_1>'' as ''<type_1>''} {,''{ByVal}<p_n>'' as ''<type_n>''}) As ''<function type>''<br>
+
Function''<name>''({{ByVal}<''p_1''> as <''type_1''>} {,{ByVal}<''p_n''> as <''type_n''>}) as <''function type''><br>
''{local variable declaration}''<br>
+
{''local variable declaration''}<br>
''{function code}''<br>
+
{''function code''}<br>
  
 
END Function
 
END Function
Line 14: Line 14:
  
 
|DESCRIPTION=
 
|DESCRIPTION=
''<name>'' is the function name.<br>
+
<''name''> is the function name.<br>
''<type_1>'' through ''<type_n>'' are the types of the parameters.<br>
+
<''type_1''> through <''type_n''> are the types of the parameters.<br>
''<p_1>'' through ''<p_n>'' are the names of the parameters passed to the function. Parameters are variables used inside the function code. When the function is called, the values of the variables are replaced by the calling values.
+
<''p_1''> through <''p_n''> are the names of the parameters passed to the function. Parameters are variables used inside the function code. When the function is called, the values of the variables are replaced by the calling values.
  
By default, parameters are passed by reference. ''{ByVal}'' is an option used to specify that the parameter is passed by value.
+
By default, parameters are passed by reference. {ByVal} is an option used to specify that the parameter is passed by value.
  
''<function type>'' is the type of the return value
+
<''function type''> is the type of the return value
  
''{local variables declaration}'' is used to declare variables local to the function (see variable scope, in this document).
+
{''local variables declaration''} is used to declare variables local to the function (see variable scope, in this document).
  
''{function code} ''defines the programming code of the algorithm which computes the value that is returned. The return value must be assigned to the ''<name>'' inside the function code.
+
{''function code''} defines the programming code of the algorithm which computes the value that is returned. The return value must be assigned to the <''name''> within function code.
  
 
The FUNCTION and END FUNCTION keywords are used to delimit a function within a task. The function(s) must appear after the main section of the code (delimited by PROGRAM….END PROGRAM). Local variables, defined using DIM, appear after the Function keyword, but before the code. Functions are executed by using the function name with its parameters in parentheses. Functions may be recursive.
 
The FUNCTION and END FUNCTION keywords are used to delimit a function within a task. The function(s) must appear after the main section of the code (delimited by PROGRAM….END PROGRAM). Local variables, defined using DIM, appear after the Function keyword, but before the code. Functions are executed by using the function name with its parameters in parentheses. Functions may be recursive.

Revision as of 10:24, 1 October 2014

{{MC-Basic |SHORT FORM=


|SYNTAX= Function<name>({{ByVal}<p_1> as <type_1>} {,{ByVal}<p_n> as <type_n>}) as <function type>
{local variable declaration}
{function code}

END Function

|AVAILABILITY= All versions

|DESCRIPTION= <name> is the function name.
<type_1> through <type_n> are the types of the parameters.
<p_1> through <p_n> are the names of the parameters passed to the function. Parameters are variables used inside the function code. When the function is called, the values of the variables are replaced by the calling values.

By default, parameters are passed by reference. {ByVal} is an option used to specify that the parameter is passed by value.

<function type> is the type of the return value

{local variables declaration} is used to declare variables local to the function (see variable scope, in this document).

{function code} defines the programming code of the algorithm which computes the value that is returned. The return value must be assigned to the <name> within function code.

The FUNCTION and END FUNCTION keywords are used to delimit a function within a task. The function(s) must appear after the main section of the code (delimited by PROGRAM….END PROGRAM). Local variables, defined using DIM, appear after the Function keyword, but before the code. Functions are executed by using the function name with its parameters in parentheses. Functions may be recursive.

|TYPE= Parmeters: Long, Double, String, Joint, Location, user defined structures, Generic Axis, Generic Group, Moving Frame (by reference only), Cam (by reference only), Comp (by reference only), Semaphore (by reference only), user defined Error and Note (by reference only).

Returned Values: Long, Double, String, Joint, Location, user defined structures, Generic Axis, Generic Group.

|RANGE=


|UNITS=


|DEFAULT=


|SCOPE= Task

|LIMITATIONS= Write only. Arrays are only passed by reference.

|EXAMPLE= Program
       ?add1(5)

End Program

Function add1(byval a as long) as long
          Add1=a+1

End Function                                                ' running this program prints 6

|SEE ALSO=

}}