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.
ValueInt32()
Method
Product:
Class:
Retrieves the 32-bit integer value of an item, typically a variable, without performing type conversion.
Syntax
Parameters
Return
int32
The 32-bit signed integer value of the item.
Remarks
⚙️ Overview
The ValueInt32() method is a direct, type-safe accessor for retrieving the 32-bit integer value of a uCalc Item. It is primarily used to get the current value of a variable that was explicitly defined with the Int32 (or Int) data type using DefineVariable.
This method is part of a family of type-specific accessors, including Value(), ValueStr(), ValueBool(), etc. Using the most specific accessor for a variable's type is more efficient than retrieving a string representation and converting it.
🛡️ Type Safety: No Implicit Conversions
A key behavior of ValueInt32() is that it does not perform type conversions. It expects the underlying data of the Item to be a 32-bit integer.
- Correct Usage: Calling
ValueInt32()on a variable defined asIntorInt32. - Incorrect Usage: If called on an Item of a different type (e.g., a
DoubleorString), it will not attempt to parse or cast the value.
This strictness ensures type integrity and prevents unexpected behavior from implicit conversions.
💡 Comparative Analysis
vs. Native Variable Access (C#/C++)In native code, you access a variable's value directly (e.g.,
int myVal = myIntObject.Value;). uCalc abstracts this behind the versatile Item object. While this adds a layer of indirection, it provides significant benefits for dynamic environments. You can write generic code that inspects anyItem—retrieving its name, type, and value through a consistent interface—which is ideal for building tools like debuggers, watch windows, or property editors.vs.
Value()andValueStr()The genericValue()andValueStr()methods are more flexible, as they will attempt to convert any numeric or string type. However,ValueInt32()is more performant when you know the variable is an integer, as it avoids the overhead of type checking and conversion.
Examples
DefineVariable examples
using uCalcSoftware;
var uc = new uCalc();
var MyVar = uc.DefineVariable("MyVar");
var MyInt = uc.DefineVariable("MyInt As Int");
var MyStr = uc.DefineVariable("MyStr As String");
uc.DefineVariable("OtherStr = 'string type inferred'");
uc.DefineVariable("MyInt16 = Int16(100/3)"); // type inferred
uc.DefineVariable("MyBool = True"); // type inferred
uc.DefineVariable("MyComplex = 3 + 4*#i"); // type inferred
MyVar.Value(123);
MyInt.ValueInt32(456);
MyStr.ValueStr("This is a test");
Console.WriteLine("MyVar = " + uc.EvalStr("MyVar"));
Console.WriteLine("MyInt = " + uc.EvalStr("MyInt"));
Console.WriteLine("MyStr = " + uc.EvalStr("MyStr"));
Console.WriteLine("OtherStr = " + uc.EvalStr("OtherStr"));
Console.WriteLine("MyInt16 = " + uc.EvalStr("MyInt16"));
Console.WriteLine("MyBool = " + uc.EvalStr("MyBool"));
Console.WriteLine("MyComplex = " + uc.EvalStr("MyComplex"));
Console.WriteLine("---");
Console.WriteLine(MyVar.Value());
Console.WriteLine(MyInt.ValueInt32());
Console.WriteLine(MyStr.ValueStr());
Console.WriteLine("---");
Console.WriteLine(uc.ItemOf("MyVar").DataType.Name);
Console.WriteLine(uc.ItemOf("MyInt").DataType.Name);
Console.WriteLine(uc.ItemOf("MyStr").DataType.Name);
Console.WriteLine(uc.ItemOf("OtherStr").DataType.Name);
Console.WriteLine(uc.ItemOf("MyInt16").DataType.Name);
Console.WriteLine(uc.ItemOf("MyBool").DataType.Name);
Console.WriteLine("---");
var Expression = "x^2 * 10";
var VarX = uc.DefineVariable("x");
var ParsedExpr = uc.Parse(Expression);
Console.Write("Expression = ");
Console.WriteLine(Expression);
for (int x = 1; x <= 10; x++) {
VarX.Value(x); // In C++ you can skip this by passing &x to DefineVariable
Console.WriteLine("x = " + VarX.ValueStr() + " Result = " + ParsedExpr.EvaluateStr());
}
ParsedExpr.Release();
VarX.Release();
MyVar = 123
MyInt = 456
MyStr = This is a test
OtherStr = string type inferred
MyInt16 = 33
MyBool = true
MyComplex = 3+4i
---
123
456
This is a test
---
double
int
string
string
int16
bool
---
Expression = x^2 * 10
x = 1 Result = 10
x = 2 Result = 40
x = 3 Result = 90
x = 4 Result = 160
x = 5 Result = 250
x = 6 Result = 360
x = 7 Result = 490
x = 8 Result = 640
x = 9 Result = 810
x = 10 Result = 1000 using uCalcSoftware; var uc = new uCalc(); var MyVar = uc.DefineVariable("MyVar"); var MyInt = uc.DefineVariable("MyInt As Int"); var MyStr = uc.DefineVariable("MyStr As String"); uc.DefineVariable("OtherStr = 'string type inferred'"); uc.DefineVariable("MyInt16 = Int16(100/3)"); // type inferred uc.DefineVariable("MyBool = True"); // type inferred uc.DefineVariable("MyComplex = 3 + 4*#i"); // type inferred MyVar.Value(123); MyInt.ValueInt32(456); MyStr.ValueStr("This is a test"); Console.WriteLine("MyVar = " + uc.EvalStr("MyVar")); Console.WriteLine("MyInt = " + uc.EvalStr("MyInt")); Console.WriteLine("MyStr = " + uc.EvalStr("MyStr")); Console.WriteLine("OtherStr = " + uc.EvalStr("OtherStr")); Console.WriteLine("MyInt16 = " + uc.EvalStr("MyInt16")); Console.WriteLine("MyBool = " + uc.EvalStr("MyBool")); Console.WriteLine("MyComplex = " + uc.EvalStr("MyComplex")); Console.WriteLine("---"); Console.WriteLine(MyVar.Value()); Console.WriteLine(MyInt.ValueInt32()); Console.WriteLine(MyStr.ValueStr()); Console.WriteLine("---"); Console.WriteLine(uc.ItemOf("MyVar").DataType.Name); Console.WriteLine(uc.ItemOf("MyInt").DataType.Name); Console.WriteLine(uc.ItemOf("MyStr").DataType.Name); Console.WriteLine(uc.ItemOf("OtherStr").DataType.Name); Console.WriteLine(uc.ItemOf("MyInt16").DataType.Name); Console.WriteLine(uc.ItemOf("MyBool").DataType.Name); Console.WriteLine("---"); var Expression = "x^2 * 10"; var VarX = uc.DefineVariable("x"); var ParsedExpr = uc.Parse(Expression); Console.Write("Expression = "); Console.WriteLine(Expression); for (int x = 1; x <= 10; x++) { VarX.Value(x); // In C++ you can skip this by passing &x to DefineVariable Console.WriteLine("x = " + VarX.ValueStr() + " Result = " + ParsedExpr.EvaluateStr()); } ParsedExpr.Release(); VarX.Release();
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto MyVar = uc.DefineVariable("MyVar");
auto MyInt = uc.DefineVariable("MyInt As Int");
auto MyStr = uc.DefineVariable("MyStr As String");
uc.DefineVariable("OtherStr = 'string type inferred'");
uc.DefineVariable("MyInt16 = Int16(100/3)"); // type inferred
uc.DefineVariable("MyBool = True"); // type inferred
uc.DefineVariable("MyComplex = 3 + 4*#i"); // type inferred
MyVar.Value(123);
MyInt.ValueInt32(456);
MyStr.ValueStr("This is a test");
cout << "MyVar = " + uc.EvalStr("MyVar") << endl;
cout << "MyInt = " + uc.EvalStr("MyInt") << endl;
cout << "MyStr = " + uc.EvalStr("MyStr") << endl;
cout << "OtherStr = " + uc.EvalStr("OtherStr") << endl;
cout << "MyInt16 = " + uc.EvalStr("MyInt16") << endl;
cout << "MyBool = " + uc.EvalStr("MyBool") << endl;
cout << "MyComplex = " + uc.EvalStr("MyComplex") << endl;
cout << "---" << endl;
cout << MyVar.Value() << endl;
cout << MyInt.ValueInt32() << endl;
cout << MyStr.ValueStr() << endl;
cout << "---" << endl;
cout << uc.ItemOf("MyVar").DataType().Name() << endl;
cout << uc.ItemOf("MyInt").DataType().Name() << endl;
cout << uc.ItemOf("MyStr").DataType().Name() << endl;
cout << uc.ItemOf("OtherStr").DataType().Name() << endl;
cout << uc.ItemOf("MyInt16").DataType().Name() << endl;
cout << uc.ItemOf("MyBool").DataType().Name() << endl;
cout << "---" << endl;
auto Expression = "x^2 * 10";
auto VarX = uc.DefineVariable("x");
auto ParsedExpr = uc.Parse(Expression);
cout << "Expression = ";
cout << Expression << endl;
for (int x = 1; x <= 10; x++) {
VarX.Value(x); // In C++ you can skip this by passing &x to DefineVariable
cout << "x = " + VarX.ValueStr() + " Result = " + ParsedExpr.EvaluateStr() << endl;
}
ParsedExpr.Release();
VarX.Release();
}
MyVar = 123
MyInt = 456
MyStr = This is a test
OtherStr = string type inferred
MyInt16 = 33
MyBool = true
MyComplex = 3+4i
---
123
456
This is a test
---
double
int
string
string
int16
bool
---
Expression = x^2 * 10
x = 1 Result = 10
x = 2 Result = 40
x = 3 Result = 90
x = 4 Result = 160
x = 5 Result = 250
x = 6 Result = 360
x = 7 Result = 490
x = 8 Result = 640
x = 9 Result = 810
x = 10 Result = 1000 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto MyVar = uc.DefineVariable("MyVar"); auto MyInt = uc.DefineVariable("MyInt As Int"); auto MyStr = uc.DefineVariable("MyStr As String"); uc.DefineVariable("OtherStr = 'string type inferred'"); uc.DefineVariable("MyInt16 = Int16(100/3)"); // type inferred uc.DefineVariable("MyBool = True"); // type inferred uc.DefineVariable("MyComplex = 3 + 4*#i"); // type inferred MyVar.Value(123); MyInt.ValueInt32(456); MyStr.ValueStr("This is a test"); cout << "MyVar = " + uc.EvalStr("MyVar") << endl; cout << "MyInt = " + uc.EvalStr("MyInt") << endl; cout << "MyStr = " + uc.EvalStr("MyStr") << endl; cout << "OtherStr = " + uc.EvalStr("OtherStr") << endl; cout << "MyInt16 = " + uc.EvalStr("MyInt16") << endl; cout << "MyBool = " + uc.EvalStr("MyBool") << endl; cout << "MyComplex = " + uc.EvalStr("MyComplex") << endl; cout << "---" << endl; cout << MyVar.Value() << endl; cout << MyInt.ValueInt32() << endl; cout << MyStr.ValueStr() << endl; cout << "---" << endl; cout << uc.ItemOf("MyVar").DataType().Name() << endl; cout << uc.ItemOf("MyInt").DataType().Name() << endl; cout << uc.ItemOf("MyStr").DataType().Name() << endl; cout << uc.ItemOf("OtherStr").DataType().Name() << endl; cout << uc.ItemOf("MyInt16").DataType().Name() << endl; cout << uc.ItemOf("MyBool").DataType().Name() << endl; cout << "---" << endl; auto Expression = "x^2 * 10"; auto VarX = uc.DefineVariable("x"); auto ParsedExpr = uc.Parse(Expression); cout << "Expression = "; cout << Expression << endl; for (int x = 1; x <= 10; x++) { VarX.Value(x); // In C++ you can skip this by passing &x to DefineVariable cout << "x = " + VarX.ValueStr() + " Result = " + ParsedExpr.EvaluateStr() << endl; } ParsedExpr.Release(); VarX.Release(); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim MyVar = uc.DefineVariable("MyVar")
Dim MyInt = uc.DefineVariable("MyInt As Int")
Dim MyStr = uc.DefineVariable("MyStr As String")
uc.DefineVariable("OtherStr = 'string type inferred'")
uc.DefineVariable("MyInt16 = Int16(100/3)") '// type inferred
uc.DefineVariable("MyBool = True") '// type inferred
uc.DefineVariable("MyComplex = 3 + 4*#i") '// type inferred
MyVar.Value(123)
MyInt.ValueInt32(456)
MyStr.ValueStr("This is a test")
Console.WriteLine("MyVar = " + uc.EvalStr("MyVar"))
Console.WriteLine("MyInt = " + uc.EvalStr("MyInt"))
Console.WriteLine("MyStr = " + uc.EvalStr("MyStr"))
Console.WriteLine("OtherStr = " + uc.EvalStr("OtherStr"))
Console.WriteLine("MyInt16 = " + uc.EvalStr("MyInt16"))
Console.WriteLine("MyBool = " + uc.EvalStr("MyBool"))
Console.WriteLine("MyComplex = " + uc.EvalStr("MyComplex"))
Console.WriteLine("---")
Console.WriteLine(MyVar.Value())
Console.WriteLine(MyInt.ValueInt32())
Console.WriteLine(MyStr.ValueStr())
Console.WriteLine("---")
Console.WriteLine(uc.ItemOf("MyVar").DataType.Name)
Console.WriteLine(uc.ItemOf("MyInt").DataType.Name)
Console.WriteLine(uc.ItemOf("MyStr").DataType.Name)
Console.WriteLine(uc.ItemOf("OtherStr").DataType.Name)
Console.WriteLine(uc.ItemOf("MyInt16").DataType.Name)
Console.WriteLine(uc.ItemOf("MyBool").DataType.Name)
Console.WriteLine("---")
Dim Expression = "x^2 * 10"
Dim VarX = uc.DefineVariable("x")
Dim ParsedExpr = uc.Parse(Expression)
Console.Write("Expression = ")
Console.WriteLine(Expression)
For x As Integer = 1 To 10
VarX.Value(x) '// In C++ you can skip this by passing &x to DefineVariable
Console.WriteLine("x = " + VarX.ValueStr() + " Result = " + ParsedExpr.EvaluateStr())
Next
ParsedExpr.Release()
VarX.Release()
End Sub
End Module
MyVar = 123
MyInt = 456
MyStr = This is a test
OtherStr = string type inferred
MyInt16 = 33
MyBool = true
MyComplex = 3+4i
---
123
456
This is a test
---
double
int
string
string
int16
bool
---
Expression = x^2 * 10
x = 1 Result = 10
x = 2 Result = 40
x = 3 Result = 90
x = 4 Result = 160
x = 5 Result = 250
x = 6 Result = 360
x = 7 Result = 490
x = 8 Result = 640
x = 9 Result = 810
x = 10 Result = 1000 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim MyVar = uc.DefineVariable("MyVar") Dim MyInt = uc.DefineVariable("MyInt As Int") Dim MyStr = uc.DefineVariable("MyStr As String") uc.DefineVariable("OtherStr = 'string type inferred'") uc.DefineVariable("MyInt16 = Int16(100/3)") '// type inferred uc.DefineVariable("MyBool = True") '// type inferred uc.DefineVariable("MyComplex = 3 + 4*#i") '// type inferred MyVar.Value(123) MyInt.ValueInt32(456) MyStr.ValueStr("This is a test") Console.WriteLine("MyVar = " + uc.EvalStr("MyVar")) Console.WriteLine("MyInt = " + uc.EvalStr("MyInt")) Console.WriteLine("MyStr = " + uc.EvalStr("MyStr")) Console.WriteLine("OtherStr = " + uc.EvalStr("OtherStr")) Console.WriteLine("MyInt16 = " + uc.EvalStr("MyInt16")) Console.WriteLine("MyBool = " + uc.EvalStr("MyBool")) Console.WriteLine("MyComplex = " + uc.EvalStr("MyComplex")) Console.WriteLine("---") Console.WriteLine(MyVar.Value()) Console.WriteLine(MyInt.ValueInt32()) Console.WriteLine(MyStr.ValueStr()) Console.WriteLine("---") Console.WriteLine(uc.ItemOf("MyVar").DataType.Name) Console.WriteLine(uc.ItemOf("MyInt").DataType.Name) Console.WriteLine(uc.ItemOf("MyStr").DataType.Name) Console.WriteLine(uc.ItemOf("OtherStr").DataType.Name) Console.WriteLine(uc.ItemOf("MyInt16").DataType.Name) Console.WriteLine(uc.ItemOf("MyBool").DataType.Name) Console.WriteLine("---") Dim Expression = "x^2 * 10" Dim VarX = uc.DefineVariable("x") Dim ParsedExpr = uc.Parse(Expression) Console.Write("Expression = ") Console.WriteLine(Expression) For x As Integer = 1 To 10 VarX.Value(x) '// In C++ you can skip this by passing &x to DefineVariable Console.WriteLine("x = " + VarX.ValueStr() + " Result = " + ParsedExpr.EvaluateStr()) Next ParsedExpr.Release() VarX.Release() End Sub End Module