Deffn ( Defines A User Function ) - Mitsubishi QD51 Programming Manual

Logic controller
Hide thumbs Also See for QD51:
Table of Contents

Advertisement

11 INSTRUCTIONS AND FUNCTIONS
DEFFN
Instruction
• Defines a user function and names it.
DEF FN <name> [( <dummy argument> [, <dummy argument> ], ...)] = <function definition
Syntax
expression>
name
dummy argument
function definition
expression
DEF FNCOT(X)=1/TAN(X)
Examples
• The DEFFN function defines a user function and names it.
Description
• 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$
• <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.
• Writing the FN instruction in the expression makes a call.
• The direct mode cannot be used with the DEF FN instruction.
11 - 49
DEFine FuNction
• • • •
Specify a name of the defined function.
• • • •
Specify a variable that is used in the function
definition expression.
• • • •
Specify an expression to calculate the value of the
function.
• • • •
Defines cot
FNCOT(X).
FNA%(X, Y) returns an integer.
FNB#(X, Y) returns a double precision value.
FNC$(X$) returns a character.
DEF FNA(X,Y)=A X+B Y Values at the time of calculating
(
1
)
χ
χ
=
as a function called
tan
FNA(X, Y) are used for A and B.
MELSEC-Q
11 - 49

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ad51h-s3Qd51-r24A1sd51s

Table of Contents