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 [..] |
|
|
Update Information |
Version |
Title |
Date |
Details |
49.48 |
Display Property Entities - DISPX, DISPY, DISPR |
29 Nov 13 |
|
* Added DISPX, DISPY, and DISPR built-in entities for display properties DISPX - Display Width - 320, 480, 640, 800 and 240, 272, 480 when rotated (S16C data) DISPY - Display Height - 240, 272, 480 and 320, 480, 640, 800 when rotated (S16C data) DISPR - Display Rotation in Degrees - 0, 90, 180, 270 (S16C data) eg LOAD(varDisplayWidth,DISPX);
|
|
49.47 |
Entity Exists Test - IF( name # 0 ? fncThen : fncElse ); |
30 Oct 13 |
|
* 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
|
|
49.46 |
Arrays of Pointers Problem |
28 Oct 13 |
|
* Fixed problem loading pointers and values into entity pointer arrays. Only the first entry could be loaded. * Added support for pointer arrays in IF() commands. * Fixed problem loading text vars from entity pointer arrays.
|
|
49.32 |
IF() - Support for multiple tests added. |
14 Feb 13 |
|
* 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.
|
|
49.19 |
IF() - Fixed logic to stop 'else' function being executed when no 'then' function is provided. |
05 Oct 12 |
|
Fixed logic to stop 'else' function being executed when no 'then' function is provided.
|
|
49.00 |
IF() - Fixed problem with using operators containing 3 characters, eg ''<>-''. |
22 Mar 12 |
|
Fixed problem with using operators containing 3 characters, eg "<>-".
|
|
48.24 |
IF() - A page name as well as the existing function name are now supported in the IF() then/else statement. |
10 Mar 12 |
|
A page name as well as the existing function name are now supported in the IF() then/else statement, thus allowing a RUN(function) or SHOW(page) to be directly called. K00-K30 are now supported in IF() test, eg IF( K03 = 1 ? func );
|
|
47.12 |
Floats - Increased maximum decimal places to 17 (was 7). |
09 Sep 11 |
|
Increased maximum decimal places to 17 (was 7). * In IF() commands, bottom nibble is now masked off fractional part of float to handle small differences in value representation.
|
|
38.00 |
IF() - Tests Added IF( v1 > -v2 ? ... ); and IF( v1 < -v2 ... ); tests. |
13 Jan 11 |
|
Added IF( v1 > -v2 ? ... ); and IF( v1 < -v2 ... ); tests, i.e. second parameter negative with less than and greater than.
|
|
30.00 |
Inline Command Blocks - enclosed in [...]'s - Commands that make calls to functions can now include the function code inline. |
24 Sep 10 |
|
Commands that make calls to functions (RUN, IF, INT,KEY) can now include the function code inline by enclosing commands in square brackets [] or call a function.
IF( VarA op VarB ? [ CmdYA(); CmdYB(); ... CmdYn(); ] : [ CmdNA(); CmdNB(); ... CmdNn(); ] );
RUN( [ CmdA(); CmdB(); ... Cmdn(); ] );
INT( Name, Buf, [ CmdA(); CmdB(); ... Cmdn(); ] );
KEY( Name, [ CmdA(); CmdB(); ... Cmdn(); ], X, Y, Style );
Examples: IF(VarA >= 50 ? [CALC(VarA,VarA,5,"-");TEXT(TxtA,VarA);;] : [LOAD(RS2,"VarA=",VarA);SHOW(PageN);] );
KEY(keyX,[CALC(varX,varX,1,"+");],123,12,stKey);
This reduces the number of lines in the file by almost 30% and keeps related code close to the action.
|
|
27.00 |
Entity Pointers - Entity pointers have been added. |
10 Sep 10 |
|
Entity pointers have been added. STYLE( PtrData, DATA ) { type = pointer; } VAR( EntPtr1, PtrData );
To set/change which entity the entity pointer is pointing to you enclose its name in quotes. LOAD( "EntPtr1", "Var1" ); // Set EntPtr1 to point to "Var1"
To access the entity pointed to by the entity pointer, do not enclose is quotes. LOAD( EntPtr1, "ABC" ); // Load the Entity pointed to by EntPtr1 with "ABC"
The following commands now support entity pointers: > LOAD(name|ptr|"ptr",num|"txt"|var|ptr,...); > CALC(var|ptr,var|ptr,num|var|ptr,"op"); > TEXT(name|ptr,"txt"|var|ptr,...); > IF(var|ptr op num|"txt"|var|ptr ? func|func_ptr : func|func_ptr); > KEY(name,func|func_ptr,...); > INT(name,buf,func|func_ptr,...); > SHOW(name|ptr,...); > HIDE(name|ptr,...); > RUN(name|func_ptr,...); > IMG(name|img_ptr,lib|img_ptr,...);
See the tu480.mnu file for an example of using pointers to update images representing CNTSECS.
|
|
19.00 |
IF() - Added IF() command with the some combinations. |
14 Jul 10 |
|
Added IF() command with the following combinations: IF( VAR1 operator VAR2 ? FUNC1 : FUNC2 ); [VAR1 and VAR2 must be the same type (ie both text strings or both numeric values)] IF( VAR1 operator NUM2 ? FUNC1 : FUNC2 ); [VAR1 must be a numeric value] IF( VAR1 operator “string2” ? FUNC1 : FUNC2 ); [VAR1 must be a text string]
Also the FUNC2 can be omitted from the IF() giving: IF( VAR1 operator VAR2 ? FUNC1 ) IF( VAR1 operator NUM2 ? FUNC1 ); IF( VAR1 operator “string2” ? FUNC1 );
|
|
|
|