uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Sets the value of a variable by parsing and evaluating a string expression, automatically handling type conversion.
This method provides a universal way to set the value of a variable by parsing and evaluating a string expression. Unlike type-specific setters (e.g., ValueInt32), this overload can assign a value to a variable of any data type, automatically handling the necessary parsing and type conversion.
The input string is not just a literal value; it is treated as a complete uCalc expression. This means it can contain calculations, function calls, or even references to other variables.
"10 * 2" will set a numeric variable to 20.Int32, setting its value with "4.75" will result in the integer 4. If an unsigned type like Byte is given a negative number, it will wrap around (e.g., -1 becomes 255).int.Parse())In most languages, converting a string to a value is a direct parsing operation (int.Parse("123")). This operation fails if the string is not a valid representation of that type. uCalc's method is more powerful because it treats the string as a full expression to be evaluated, not just parsed. This allows for runtime calculations to determine the final value.
In a compiled language, you assign a pre-computed value: myVar = 5 * 2;. With this Value() overload, you provide the formula as a string: MyVar.Value("5 * 2");. This is fundamental for building applications where logic is determined at runtime, such as scripting engines or spreadsheet applications. It decouples the value assignment from the compile-time logic of the host application.
This method should be used for variables created with DefineVariable or Define.
ID: 25
using uCalcSoftware;
var uc = new uCalc();
var Int32Var = uc.DefineVariable("Int32Var As Int32");
var ByteVar = uc.DefineVariable("ByteVar As Byte");
var StrVar = uc.DefineVariable("StrVar As String");
var SngVar = uc.DefineVariable("SngVar As Single");
Int32Var.Value("4.25"); // Will be converted to integer
ByteVar.Value("-1"); // Will be converted to unsigned byte
StrVar.Value("'Test'");
SngVar.Value("1 + 0.25");
Console.WriteLine(uc.Eval("Int32Var"));
Console.WriteLine(uc.Eval("ByteVar"));
Console.WriteLine(uc.EvalStr("StrVar"));
Console.WriteLine(uc.EvalStr("SngVar"));
4
255
Test
1.25 using uCalcSoftware; var uc = new uCalc(); var Int32Var = uc.DefineVariable("Int32Var As Int32"); var ByteVar = uc.DefineVariable("ByteVar As Byte"); var StrVar = uc.DefineVariable("StrVar As String"); var SngVar = uc.DefineVariable("SngVar As Single"); Int32Var.Value("4.25"); // Will be converted to integer ByteVar.Value("-1"); // Will be converted to unsigned byte StrVar.Value("'Test'"); SngVar.Value("1 + 0.25"); Console.WriteLine(uc.Eval("Int32Var")); Console.WriteLine(uc.Eval("ByteVar")); Console.WriteLine(uc.EvalStr("StrVar")); Console.WriteLine(uc.EvalStr("SngVar"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto Int32Var = uc.DefineVariable("Int32Var As Int32");
auto ByteVar = uc.DefineVariable("ByteVar As Byte");
auto StrVar = uc.DefineVariable("StrVar As String");
auto SngVar = uc.DefineVariable("SngVar As Single");
Int32Var.Value("4.25"); // Will be converted to integer
ByteVar.Value("-1"); // Will be converted to unsigned byte
StrVar.Value("'Test'");
SngVar.Value("1 + 0.25");
cout << uc.Eval("Int32Var") << endl;
cout << uc.Eval("ByteVar") << endl;
cout << uc.EvalStr("StrVar") << endl;
cout << uc.EvalStr("SngVar") << endl;
}
4
255
Test
1.25 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto Int32Var = uc.DefineVariable("Int32Var As Int32"); auto ByteVar = uc.DefineVariable("ByteVar As Byte"); auto StrVar = uc.DefineVariable("StrVar As String"); auto SngVar = uc.DefineVariable("SngVar As Single"); Int32Var.Value("4.25"); // Will be converted to integer ByteVar.Value("-1"); // Will be converted to unsigned byte StrVar.Value("'Test'"); SngVar.Value("1 + 0.25"); cout << uc.Eval("Int32Var") << endl; cout << uc.Eval("ByteVar") << endl; cout << uc.EvalStr("StrVar") << endl; cout << uc.EvalStr("SngVar") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim Int32Var = uc.DefineVariable("Int32Var As Int32")
Dim ByteVar = uc.DefineVariable("ByteVar As Byte")
Dim StrVar = uc.DefineVariable("StrVar As String")
Dim SngVar = uc.DefineVariable("SngVar As Single")
Int32Var.Value("4.25") '// Will be converted to integer
ByteVar.Value("-1") '// Will be converted to unsigned byte
StrVar.Value("'Test'")
SngVar.Value("1 + 0.25")
Console.WriteLine(uc.Eval("Int32Var"))
Console.WriteLine(uc.Eval("ByteVar"))
Console.WriteLine(uc.EvalStr("StrVar"))
Console.WriteLine(uc.EvalStr("SngVar"))
End Sub
End Module
4
255
Test
1.25 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim Int32Var = uc.DefineVariable("Int32Var As Int32") Dim ByteVar = uc.DefineVariable("ByteVar As Byte") Dim StrVar = uc.DefineVariable("StrVar As String") Dim SngVar = uc.DefineVariable("SngVar As Single") Int32Var.Value("4.25") '// Will be converted to integer ByteVar.Value("-1") '// Will be converted to unsigned byte StrVar.Value("'Test'") SngVar.Value("1 + 0.25") Console.WriteLine(uc.Eval("Int32Var")) Console.WriteLine(uc.Eval("ByteVar")) Console.WriteLine(uc.EvalStr("StrVar")) Console.WriteLine(uc.EvalStr("SngVar")) End Sub End Module