474 Appendix A
Additional Lab Exercises
General Programming Techniques
Solution—Testing Numbers, Step 2
Figure A-4 shows the solution to the Testing Numbers exercise with four
objects.
Figure A-4. Testing Numbers, Step 2
Key Points
n Auto Execute: All input objects such as the
Int32 Slider have an
Auto Execute selection in the Properties Box. If chosen, the
object operates whenever its value is changed without needing to press
Start or the Run button.
n Eliminating Gates: The expression
(A>=50)*A in the If/Then/Else
object evaluates to a
1*A, if A>=50 is true, or 0, if false. So A is put on
the
Then pin, if the expression is true, and a 0 is put on the Else pin, if
the expression is false. (Any expression that evaluates to a non-zero is
considered true, and the value is propagated on the
Then pin.)
Testing Numbers, Step 3
Create a solution using only three objects.
Hint: Use a triadic expression in the
Formula object. The format is:
(<expression> ? <if TRUE,output value> : <if FALSE, output value>).
For example, if
A < 10 evaluates to TRUE, you want the value of A on the
Result pin; otherwise, you want the string “FALSE” on the Result pin.
You would use the following triadic expression:
(A<10 ? A : "FALSE").