Command |
IF |
|
|
Description |
Compare variables, buffers or text for value or length.
If true, do function1, if false do function2 (optional).
The ~ operator types can compare text length with another text or a
numeric length.
When comparing floating point numbers (max 17 decimal places - v47.12) the lowest
bit is masked prior to comparison. |
|
|
Syntax/Parameters |
IF(Var~Var?Function1:Function2) |
|
|
Options |
The operators allowed for numeric
values are:
=, == equal to
<>, != not equal to
< less
than
> greater
than
<= less than or
equal to
>= greater
than or equal to
+ sum
not equal to zero
- difference
not equal to zero
* multiplication
not equal to zero
/ division
not equal to zero
% modulus
not equal to zero
& logical
AND
| logical
OR
^ logical
exclusive-OR
=- equal
to the negative of
&& Boolean
AND
|| Boolean
OR |
The operators allowed for text strings
are:
=, == equal to
>
greater than
<
less than
>=
greater than or equal to
<=
less than or equal to
<>, !=
not equal
~=
same text length
~<
text length shorter than
~>
text length longer than
~!
not same text length |
IF() - Multiple tests - v49.32
Support for multiple tests added.
IF( AopB AND CopD OR EopF AND GopH ? funcY : funcN );
"op" is one of the existing operators (=, !=, > etc).
Use AND or OR between pairs of comparisons. Comparisons are performed left to right.
Entity Exists Test -
IF( name # 0 ? fncThen : fncElse ); - v49.47
* New operator '#' added to test if
entity exists
* The result of ‘#’ is 1 for “exists” or 0 for “not exists”.
* The result of ‘!#’ is 1 for “not exists” or 0 for “exists”.
IF( entName # 0 ? fncThen : fncElse ); // entName does not exist: do
"fncThen" else do "fncElse"
IF( entName # 1 ? fncThen : fncElse ); // entName exists: do "fncThen"
else do "fncElse"
IF( entName !# 1 ? fncThen : fncElse ); // entName does not exist:
do "fncThen" else do "fncElse"
IF( entName !# 0 ? fncThen : fncElse ); // entName exists: do "fncThen"
else do "fncElse"
Example:
IF(varTest#1?[LOAD(RS2,"Y");]:[LOAD(RS2,"N");]); // outputs N
IF(varTest!#1?[LOAD(RS2,"Y");]:[LOAD(RS2,"N");]); // outputs Y
IF(varTest#0?[LOAD(RS2,"N");]:[LOAD(RS2,"Y");]); // outputs N
IF(varTest!#0?[LOAD(RS2,"N");]:[LOAD(RS2,"Y");]); // outputs Y
VAR(varTest,0,U8);
IF(varTest#1?[LOAD(RS2,"Y");]:[LOAD(RS2,"N");]); // outputs Y
IF(varTest!#1?[LOAD(RS2,"Y");]:[LOAD(RS2,"N");]); // outputs N
IF(varTest#0?[LOAD(RS2,"N");]:[LOAD(RS2,"Y");]); // outputs Y
IF(varTest!#0?[LOAD(RS2,"N");]:[LOAD(RS2,"Y");]); // outputs N
|
|
|
Example |
IF(K0=“L”?HELPFNC); //single condition
IF(HIGHVAL < ACTVAL ? HIGHFUNC : LOWFUNC);
IF(STRVAR~>0? SHOWFUNC); //if STRVAR length > 0 show
data
IF(STARVAL >= -STARTMP?SHOWSTAR);
IF(STARVAL > 0? [ LOAD(vReqd,15); TEXT(txtCurFlr,"15"); RUN(fncGo);
] ); //uses in line code [..] |
|
|
|