Hey developers! π Today we're diving into one of the fundamental building blocks of Uniface ProcScript - the if/endif conditional block. This comprehensive guide is based on the official Uniface documentation 10.4, and I had some assistance from AI to put this together for you.
π What is the if/endif Block?
The if/endif block in Uniface allows you to execute ProcScript conditionally based on logical expressions. Think of it as your decision-making tool in code! π€
π Basic Syntax
if ( Condition 1 )
... one or more ProcScript statements ...
{elseif ( Condition 2 )
... one or more ProcScript statements ...
elseif ( Condition n )
... one or more ProcScript statements ... }
{else
... one or more ProcScript statements ... }
endif
π§ Key Components
Clause | Description |
---|---|
if |
Defines a condition and marks the ProcScript to be executed if the condition is met |
elseif |
Defines an alternative condition and marks the ProcScript to be executed if this condition is met |
else |
Marks the ProcScript to be executed if none of the previous conditions have been met |
endif |
Marks the end of the if conditional block |
β‘ How It Works
The magic happens through sequential evaluation! β¨ Each condition is evaluated in order, starting with the if
statement. When a condition evaluates to TRUE
, the corresponding ProcScript statements are executed, and the rest of the block is skipped.
If no conditions are met and there's an else
clause, those statements will execute. No else
clause means no execution if all conditions fail.
π― Practical Examples
Example 1: Conditional Printing π¨οΈ
Here's how you can use if/endif for conditional printing operations:
trigger leavePrinted
AMOUNT.SUBTOTAL = (AMOUNT.SUBTOTAL + INVAMOUNT)
if (INVDATE != $next(INVDATE)) ; if next invoice date different
printbreak "SUBTOTAL" ; print "SUBTOTAL" break frame
AMOUNT.SUBTOTAL = 0 ; set subtotal to 0
eject ; start printing on next page
else
skip ; print next line empty
endif
end; leavePrinted
Example 2: Alphabetic Range Detection π€
This example shows how to determine the alphabetic range of a field:
$1 = NAME[1:1]
if ($1 < "M")
message "NAME starts A-L"
elseif ($1 > "M")
message "NAME starts N-Z"
else
message "NAME starts M"
endif
π‘ Pro Tips
- Nesting Power: You can nest conditional statements up to 32 levels deep! ποΈ
- Single-Line Shortcuts: For single ProcScript statements, you can write them on the same line as the condition
- Multiple elseif: Use as many
elseif
clauses as you need - Boolean Conversion: Uniface automatically converts data types to boolean for condition evaluation
πͺ Where Can You Use It?
The best part? The if/endif block is allowed in all component types in Uniface! This makes it incredibly versatile for any scenario you encounter.
π Conclusion
Mastering the if/endif block is essential for any Uniface developer. It's your gateway to creating intelligent, responsive applications that can make decisions based on data and user interactions. π―
Happy coding, and may your conditions always evaluate as expected! π
Top comments (0)