Hello everyone! π If you're working with Rocket Uniface, you know it's a powerful platform for building robust enterprise applications. Sometimes, however, the most fundamental concepts are the ones we need to understand best. Today, we're diving into a core building block of Uniface's ProcScript: the boolean data type.
(Disclaimer: This post was drafted with the assistance of an AI to help explain the official Uniface documentation in a simple way.)
What is a boolean in Uniface?
At its heart, a boolean is a data type used to represent two states: TRUE or FALSE. It's the foundation of all logical operations in your application. Think of it as a simple switch that can be either on or off. In Uniface, this is crucial for controlling application flow with if/else statements, managing flags, or checking the status of an operation.
How to Declare a boolean π
In ProcScript, you can declare a boolean in two main ways: as a variable within your script or as a parameter for a component's operation.
1. As a Variable:
You declare it directly within a variables block. This is perfect for temporary flags or state management inside your script.
variables
boolean isCustomerActive
endvariables
; Later in your script...
isCustomerActive = "1" ; Set it to TRUE
2. As a Parameter:
You can define a boolean as an input (IN), output (OUT), or input/output (INOUT) parameter in a params block. This is how you pass true/false values between different parts of your application.
params
boolean pCreditApproved : INOUT
endparams
; Check the parameter
if (pCreditApproved)
; Do something if credit is approved
else
; Do something else
endif
The "Truthy" and "Falsy" World of Uniface Booleans π€
This is where Uniface has a specific and important behavior! Unlike some other languages that are very strict, Uniface is quite flexible in how it interprets values as TRUE or FALSE.
What is considered FALSE? β
Uniface will interpret the following values as FALSE:
- An empty value (
"") - The number
0 - The characters
Forf(for False) - The characters
Norn(for No)
What is considered TRUE? β
This is the simple part: everything else is TRUE!
Yes, you read that right. Any value that is not in the "FALSE" list above will be evaluated as TRUE. This includes:
- The number
1(the most common way to represent TRUE) - Any other number, like
-1or42 - The characters
TorY - Any non-empty string, like
"Hello"
A Practical Example
Let's see this in action. Imagine a script that checks if a user's subscription is active.
variables
boolean vSubscriptionActive
endvariables
; Let's test different values
vSubscriptionActive = "1"
if (vSubscriptionActive)
message "Subscription is Active! (Value was 1)"
endif
vSubscriptionActive = "n"
if (!vSubscriptionActive) ; The '!' means 'not'
message "Subscription is NOT Active. (Value was n)"
endif
vSubscriptionActive = "some_random_text"
if (vSubscriptionActive)
message "Subscription is surprisingly Active! (Value was 'some_random_text')"
endif
vSubscriptionActive = ""
if (!vSubscriptionActive)
message "Subscription is NOT Active. (Value was empty)"
endif
Key Takeaway π
The Uniface boolean type is flexible, but you need to be careful. The rule "everything that is not explicitly false is true" can be a powerful feature but also a source of bugs if you are not aware of it.
My advice? Stick to using 1 for TRUE and 0 for FALSE in your code. This makes your intentions clear and your application more predictable.
Happy coding! π»
Top comments (0)