Difference between revisions of "QVAL"

From SphereWiki
Jump to: navigation, search
(Created page with "QVAL is used to test if an arguement is true or false in a single line of code. <QVAL <EVAL <LOCAL.A>+1> < <LOCAL.B>? SYSMESSAGE LOCAL.A IS SMALLER:SYSMESSAGE LOCAL.B IS S...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
QVAL is used to test if an arguement is true or false in a single line of code.
+
==The first QVAL Syntax==
  
<QVAL <EVAL <LOCAL.A>+1> < <LOCAL.B>?   SYSMESSAGE LOCAL.A IS SMALLER:SYSMESSAGE LOCAL.B IS SMALLER>
+
<QVAL CONDITION ? TRUE : FALSE>
  
In the above statement is we say that local.a = 3 and local.b = 5
+
QVAL is a simple form of the IF-ELSE structure. It is used to test if an argument is true or false in a single line of code.
  
Then local.a+1 = 4
+
For example, this:
  
4 being less that 5 means that the argument will return as true and so the first output in the true:false condition will be given
+
IF (<EVAL <LOCAL.A>+1> < <LOCAL.B>)
 +
    SYSMESSAGE A+1 is smaller than B
 +
ELSE
 +
    SYSMESSAGE A+1 is greater than or equal to B
 +
ENDIF
  
If local.a = 5 and local.b = 5
+
...is the same as:
  
Then local.a+1 = 6
+
<QVAL <EVAL <LOCAL.A>+1> < <LOCAL.B> ? SYSMESSAGE A+1 is smaller than B:SYSMESSAGE A+1 is greater than or equal to B>
  
In these circumstances the argument will return as false and so the condition after : being the false output will be given.
+
In the above statement, if we say that local.a=3 and local.b=5, then local.a+1=4
  
The argument does not have to be greater than or less than, it can also be equal to or even if a specific indicator such as a tag or defname just exists.
+
Since 4 is less that 5, the condition is true, and so the first output (before the : sign) in the true:false condition will be executed
  
 +
If local.a=5 and local.b=5, then local.a+1=6
  
Your argument must always be ended with a ?
+
Since 6 is not less than 5, the condition will return as false and the second output (after the : sign) in the true:false result will be executed.
  
Must always have 2 possible outputs TRUE:FALSE
+
Your "if condition" is separated from the results by the ? character.  The true and false results are separated by the : character (which is mandatory, even if you dont want anything to happen in one of the cases.)
  
And is closed with a >
+
Be careful if the true:false conditions also require you to use "greater than"  It is easy to inadvertently close an argument too soon with a misplaced > after the ? or : in a QVAL argument. You should use always Less than ( < ) or Less or Equal ( <= )
  
  
Be careful if the true:false conditions also require you to use "greater than"  It is easy to inadvertently close an argument too soon with a misplaced > after the ? or : in a QVAL argument.
+
==The second QVAL Syntax==
  
---------------------------------------------------------------------------------------------------------------------------------------------
+
QVAL(VALUE1,VALUE2,LESSTHAN,EQUAL,GREATERTHAN)
  
 +
This form of the QVAL statement is useful when comparing two values.
  
 +
For example:
  
QVAL(test1,test2,res1,res2,res3) in addition to current <QVAL?:> variant. It is useful if dealing with numbers without many IF-s.
+
<eval qval(<VAR.X>,<VAR.Y>,<VAR.ONE>,<VAR.TWO>,<VAR.THREE>)>
Sample <eval qval(<VAR.X>,<VAR.Y>,<VAR.ONE>,<VAR.TWO>,<VAR.THREE>)> will return <VAR.ONE> if <VAR.X> < <VAR.Y>, <VAR.TWO> if they are equal, and <VAR.THREE> if the it is greater. If some of the arguments are omited like qval(1,2,,3) it will default to zero
+
 
 +
...will return <VAR.ONE> if X is less than Y, <VAR.TWO> if they are equal, and <VAR.THREE> if X greater than Y. If some of the arguments are omited like qval(1,2,,3) it will default to zero.

Latest revision as of 20:44, 28 November 2013

The first QVAL Syntax

<QVAL CONDITION ? TRUE : FALSE>

QVAL is a simple form of the IF-ELSE structure. It is used to test if an argument is true or false in a single line of code.

For example, this:

IF (<EVAL <LOCAL.A>+1> < <LOCAL.B>)
   SYSMESSAGE A+1 is smaller than B
ELSE
   SYSMESSAGE A+1 is greater than or equal to B
ENDIF

...is the same as:

<QVAL <EVAL <LOCAL.A>+1> < <LOCAL.B> ? SYSMESSAGE A+1 is smaller than B:SYSMESSAGE A+1 is greater than or equal to B>

In the above statement, if we say that local.a=3 and local.b=5, then local.a+1=4

Since 4 is less that 5, the condition is true, and so the first output (before the : sign) in the true:false condition will be executed

If local.a=5 and local.b=5, then local.a+1=6

Since 6 is not less than 5, the condition will return as false and the second output (after the : sign) in the true:false result will be executed.

Your "if condition" is separated from the results by the ? character. The true and false results are separated by the : character (which is mandatory, even if you dont want anything to happen in one of the cases.)

Be careful if the true:false conditions also require you to use "greater than" It is easy to inadvertently close an argument too soon with a misplaced > after the ? or : in a QVAL argument. You should use always Less than ( < ) or Less or Equal ( <= )


The second QVAL Syntax

QVAL(VALUE1,VALUE2,LESSTHAN,EQUAL,GREATERTHAN)

This form of the QVAL statement is useful when comparing two values.

For example:

<eval qval(<VAR.X>,<VAR.Y>,<VAR.ONE>,<VAR.TWO>,<VAR.THREE>)>

...will return <VAR.ONE> if X is less than Y, <VAR.TWO> if they are equal, and <VAR.THREE> if X greater than Y. If some of the arguments are omited like qval(1,2,,3) it will default to zero.