Difference between revisions of "Boolean"

From Team Developer SqlWindows Wiki
Jump to: navigation, search
m
 
Line 29: Line 29:
 
</pre>
 
</pre>
 
*Evaluate expressions in parentheses first.
 
*Evaluate expressions in parentheses first.
<br>
+
 
 +
 
 +
Example:
 +
 
 +
<pre>
 +
  If bOk OR SalMessageBox( "Error occurred : continue?", "Continue?", MB_YesNo ) = IDYES
 +
      ! Continue processing
 +
  Else
 +
      ! Stop processing
 +
</pre>
 +
 
 +
 
 +
The above sample has two boolean expressions, the bOk and the result of the SalMessageBox.<br>
 +
The OR in between them will result in:<br>
 +
* When bOk = TRUE, the expression AFTER the OR will NOT be executed. So the messagebox will NOT be shown
 +
* When bOk = FALSE, the expression AFTER the OR will be executed. So the messagebox is shown. The result is then evaluated
 +
 
 +
When the user clicks YES, the expression will be (FALSE OR TRUE) -> TRUE
 +
When the user clicks NO, the expression will be (FALSE OR FALSE) -> FALSE
  
  

Latest revision as of 11:41, 16 July 2013

Boolean datatype


Contents


Pointer2.png How are expressions evaluated Pointer.png

Team Developer uses these precedence rules to evaluate expressions:

  • Evaluate expressions with AND, OR, and NOT from left to right.
   If bError OR bStop
   !
   ! bError will be evaluated first, then bStop
  • Stop evaluating AND/OR as soon as the result is known.
   If bError OR bStop
   !
   ! When bError is TRUE, bStop will not be evaluated
   ! When bError is FALSE, bStop will be evaluated
   !
   If bError AND bStop
   !
   ! When bError is TRUE, bStop will be evaluated
   ! When bError is FALSE, bStop will not be evaluated
  • Evaluate expressions in parentheses first.


Example:

   If bOk OR SalMessageBox( "Error occurred : continue?", "Continue?", MB_YesNo ) = IDYES
      ! Continue processing
   Else
      ! Stop processing


The above sample has two boolean expressions, the bOk and the result of the SalMessageBox.
The OR in between them will result in:

  • When bOk = TRUE, the expression AFTER the OR will NOT be executed. So the messagebox will NOT be shown
  • When bOk = FALSE, the expression AFTER the OR will be executed. So the messagebox is shown. The result is then evaluated

When the user clicks YES, the expression will be (FALSE OR TRUE) -> TRUE When the user clicks NO, the expression will be (FALSE OR FALSE) -> FALSE


Pointer2.png What is a boolean in TD ? Pointer.png

Internally, the boolean datatype is the same as the Number datatype.
The only difference between a Number and a Boolean is purely visual in the outline.
This means that you can assign any value to a Boolean, use them as it were normal numbers.

So beware, the next piece of code shows strange effects can happen when you are not aware of this

   Set bValue = 5
   If bValue = TRUE
      ...
   Else
      ! It evaluates to FALSE here
   If bValue
      ! It evaluates to TRUE here
   Else
      ...


So the best way to evaluate booleans is never use the TRUE or FALSE keywords.

   If bValue
      ! when boolean has any (negative) value except FALSE, 0, NUMBER_Null
   Else
      ! when boolean is FALSE, 0 or NUMBER_Null