11 - 49 11 - 49
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
DEFFN
Instruction
DEFine FuNction
• Defines a user function and names it.
DEF FN <name> [( <dummy argument> [, <dummy argument> ], …)] = <function definition
expression>
name
• • • •
Specify a name of the defined function.
dummy argument
• • • •
Specify a variable that is used in the function
definition expression.
Syntax
function definition
expression
• • • •
Specify an expression to calculate the value of the
function.
Examples
DEF FNCOT(X)=1/TAN(X)
• • • •
Defines cot
χ
as a function called
FNCOT(X).
Description
• The DEFFN function defines a user function and names it.
• When using a function that is not provided by BASIC, the user has to write the function.
The user can freely define the function using the DEF FN instruction.
• <name> is used to call the function defined by the DEF FN instruction from the FN
instruction, and name it by the same rule for a variable name. If a type specification
character (%, !, #, $) is attached to <name>, the defined function returns a value of that
type. If a type specification character is not attached, a single precision value is returned.
Example
DEF FNA%(X, Y)=X+Y
DEF FNB#(X, Y)=X/Y
DEF FNC$(X$)=”OK”+X$
FNA%(X, Y) returns an integer.
FNB#(X, Y) returns a double precision value.
FNC$(X$) returns a character.
• <dummy argument> is a variable used by the function’s definition expression, and is
replaced by <real argument> and calculated according to the constant expression of the
function. <dummy argument> may be omitted.
(You can define a function without arguments.)
• The definition expression of the function defines the calculation method of the function, and
is described within one line (255 characters for the entire DEF FN statement.)
• The variables listed in the definition expression of the function is just for defining the
calculation format, and the values are not changed nor referred to even if the same
variable is used in the program. In addition, it is not necessary to use all variables as
<dummy argument>. If is not used as <dummy argument>, the variable value at that
moment is used for calculation.
DEF FNA(X,Y)=A X+B Y
Values at the time of calculating
FNA(X, Y) are used for A and B.
• Writing the FN instruction in the expression makes a call.
• The direct mode cannot be used with the DEF FN instruction.
χ
1
tan
=
)
(