SetNullHandling
You can use the SetNullhandling function in Optiva equations to set a global flag for all equations to interpret empty parameter values as zero or null.
The function provides consistent handling of empty parameter values throughout equation values.
When to use
You can use this function to:
- Establish consistent behavior across all equations for handling empty parameter values.
- Set empty parameter values to zero (1) when calculations require numeric default values instead of null values.
- Set empty parameter values to zero (0) to avoid null-reference errors in mathematical operations.
When not to use
You cannot use this function if different equations require different null-handling behavior because the setting applies globally.
Syntax
void SetNullHandling(int value);
Parameter
| Parameter | Type | Required | Description |
|---|---|---|---|
value |
int | Yes | The flag that determines how empty values are handled. Possible values:
|
Prerequisites
- This function sets a global flag for all equations.
- If you use this function for one equation, you must use it for all equations.
- The setting applies to all equations executed after this function is called.
Examples
- Example 1
-
Treat Empty Values as Zero.
SetNullHandling(1);
- Example 2
-
Using Flag = 1 (Zero) for Calculations.
// Treat empty values as zero for calculations SetNullHandling(1); // If PROTEIN parameter is empty, it's treated as 0 double protein = Convert.ToDouble(Param("PROTEIN")); // Returns 0 if empty double fat = Convert.ToDouble(Param("FAT")); // Returns 0 if empty // Calculate total (empty values don't cause null errors) double total = protein + fat; MessageList($"Total: {total}"); // Works even if parameters are empty
- Example 3
-
Treat Empty Values as Null.
SetNullHandling(0);
- Example 4
-
Using Flag = 0 (Null) for Null-Aware Logic.
// Treat empty values as null for null-aware logic SetNullHandling(0); // Check if parameter has a value string proteinStr = Param("PROTEIN"); if (string.IsNullOrEmpty(proteinStr)) { MessageList("PROTEIN parameter is null/empty"); // Handle null case } else { double protein = Convert.ToDouble(proteinStr); MessageList($"PROTEIN value: {protein}"); }