uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
ValueBool()
Method
Product:
Class:
Retrieves the boolean value of a uCalc Item, with automatic type coercion from other data types.
Syntax
Parameters
Return
bool
Returns true or false representing the item's value. Performs type coercion if the item is not a boolean.
Remarks
The ValueBool() method is the accessor for retrieving the value of a uCalc Item as a boolean. It is the getter counterpart to the ValueBool(bool) setter.
This method is typically used on variables that have been explicitly defined as boolean using DefineVariable:
var myFlag = uc.DefineVariable("myFlag As Bool = true");Console.WriteLine(myFlag.ValueBool()); // Outputs True
Automatic Type Coercion
A key feature of ValueBool() is its ability to perform type coercion at runtime. If the Item is not a boolean, uCalc will attempt to convert its value according to these rules:
- Numeric Types (
Int,Double, etc.): A value of0is converted tofalse. Any non-zero value is converted totrue. - String Types: An empty string (
"") is converted tofalse. Any non-empty string is converted totrue.
This behavior makes it easy to write flexible conditional logic without needing to manually check and convert types.
Comparative Analysis
vs. Native Properties (C#/C++): In a statically-typed language, you would access a boolean property directly (e.g.,
myObject.IsEnabled). A uCalc Item is a generic, type-aware container. TheValueBool()method is a specialized accessor that queries theItemfor its value and returns it as a specific type. This is closer to working with aDictionary<string, object>or avarianttype, where you must cast or convert the value after retrieving it. uCalc simplifies this by providing direct, type-safe accessor methods.Why uCalc?: The power lies in runtime introspection. You can retrieve an Item by its string name and then dynamically query its value as a boolean, all without compile-time knowledge of the variable. This is fundamental for building dynamic scripting and configuration engines.
Examples
Checking if a uCalc object is the default with IsDefault
using uCalcSoftware;
var uc = new uCalc();
var Status = uc.DefineVariable("Status As Bool");
Console.WriteLine(Status.ValueBool());
var MyuCalc = new uCalc();
Status.ValueBool(MyuCalc.IsDefault);
Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"));
MyuCalc.IsDefault = true;
Status.ValueBool(MyuCalc.IsDefault);
Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"));
False
MyuCalc is the current default? false
MyuCalc is the current default? true using uCalcSoftware; var uc = new uCalc(); var Status = uc.DefineVariable("Status As Bool"); Console.WriteLine(Status.ValueBool()); var MyuCalc = new uCalc(); Status.ValueBool(MyuCalc.IsDefault); Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'")); MyuCalc.IsDefault = true; Status.ValueBool(MyuCalc.IsDefault); Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
auto Status = uc.DefineVariable("Status As Bool");
cout << tf(Status.ValueBool()) << endl;
uCalc MyuCalc;
Status.ValueBool(MyuCalc.IsDefault());
cout << uc.EvalStr("$'MyuCalc is the current default? {Status}'") << endl;
MyuCalc.IsDefault(true);
Status.ValueBool(MyuCalc.IsDefault());
cout << uc.EvalStr("$'MyuCalc is the current default? {Status}'") << endl;
}
False
MyuCalc is the current default? false
MyuCalc is the current default? true #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; auto Status = uc.DefineVariable("Status As Bool"); cout << tf(Status.ValueBool()) << endl; uCalc MyuCalc; Status.ValueBool(MyuCalc.IsDefault()); cout << uc.EvalStr("$'MyuCalc is the current default? {Status}'") << endl; MyuCalc.IsDefault(true); Status.ValueBool(MyuCalc.IsDefault()); cout << uc.EvalStr("$'MyuCalc is the current default? {Status}'") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim Status = uc.DefineVariable("Status As Bool")
Console.WriteLine(Status.ValueBool())
Dim MyuCalc As New uCalc()
Status.ValueBool(MyuCalc.IsDefault)
Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"))
MyuCalc.IsDefault = true
Status.ValueBool(MyuCalc.IsDefault)
Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'"))
End Sub
End Module
False
MyuCalc is the current default? false
MyuCalc is the current default? true Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim Status = uc.DefineVariable("Status As Bool") Console.WriteLine(Status.ValueBool()) Dim MyuCalc As New uCalc() Status.ValueBool(MyuCalc.IsDefault) Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'")) MyuCalc.IsDefault = true Status.ValueBool(MyuCalc.IsDefault) Console.WriteLine(uc.EvalStr("$'MyuCalc is the current default? {Status}'")) End Sub End Module