uCalc API Version: 2.1.3-preview.2 Released: 6/16/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.
DefineVariable
Method
Product:
Class:
Defines a new variable or array within the uCalc engine, with an optional initial value and data type.
Syntax
Parameters
Return
Item
An Item object representing the newly defined variable.
Remarks
DefineVariable is the primary method for creating variables and arrays within a uCalc instance. It uses a flexible string-based syntax that allows for defining a variable's name, data type, and initial value in a single statement. This is the counterpart to DefineConstant, with the key difference that variables can be modified at runtime.
⚙️ Syntax Breakdown
The definition string follows a simple pattern:
"VariableName [As DataType] [= InitialValueExpression]"
- VariableName: The name of the variable. Must follow the alphanumeric token rules, which can be inspected via
uc.ItemOf("_Token_Alphanumeric").Regex(). As DataType(Optional): Explicitly assigns a data type (e.g.,Int,String,Bool).= InitialValueExpression(Optional): Assigns an initial value. The expression is evaluated, and its result becomes the variable's starting value.
If no initial value is provided, the variable is initialized to the default for its type (e.g., 0 for numbers, "" for strings).
💡 Type System
uCalc employs a flexible type system for variables:
- Explicit Typing: Use the
Askeyword to specify a type (e.g.,"MyInt As Int"). - Type Inference: If
Asis omitted but an initial value is given, uCalc infers the type (e.g.,"MyStr = 'hello'"becomes aString). - Default Typing: If neither a type nor an initial value is specified, the variable receives the engine's default data type, which can be managed with DefaultDataType.
- Pointer Types: Append
Ptrto a data type name to create a pointer variable (e.g.,Int Ptr).
By default, variable names are not case-sensitive.
📊 Defining Arrays
You can define arrays in two ways:
Fixed-Size Declaration: Specify the size within square brackets.
uc.DefineVariable("MyArray[10] As Int"); // An array of 10 integersInitializer List: Leave the brackets empty and provide a comma-separated list of initial values in curly braces. The size is inferred from the list.
uc.DefineVariable("MyStrings[] = {'apple', 'banana', 'cherry'}");
🔗 Memory Binding
A powerful feature of DefineVariable is its ability to bind a uCalc variable directly to a variable in your host application (C#, C++, etc.) via the variableAddress parameter. This creates a two-way link:
- Changes to the host variable are immediately reflected in uCalc.
- Changes made to the variable within a uCalc expression (e.g.,
Eval("myVar = 10")) directly modify the memory of the host variable.
This technique avoids the need for manually updating variables before each evaluation and is highly efficient. In C++, you can pass an address directly (e.g., &myHostVar). In C#, this typically requires pinning the object in memory using GCHandle within an unsafe context.
🆚 Comparative Analysis
vs. Statically-Typed Languages (C#, C++)
- Declaration: In C# or C++, variables are declared with compile-time type safety (
int x = 10;). uCalc's string-based approach ("x = 10") is dynamic, evaluated at runtime. - Flexibility: uCalc's method is ideal for scripting, configuration files, or user-defined formulas where variable names and types are not known at compile time.
- Safety: The trade-off is a lack of compile-time checking. A typo in a variable name (
"MyVarr = 10") will result in a runtime error, not a compiler error.
vs. Dynamic Languages (Python, JavaScript)
- Syntax: The concept is similar to dynamic languages where variables are created on first assignment. However, uCalc provides optional strong typing (
As Int), which is more akin to TypeScript than plain JavaScript.
The unique advantage of DefineVariable lies in its memory binding capability, which provides a level of integration with native code that is uncommon in most high-level expression evaluators.
To see all defined variables, you can use ListOfItems with the property ItemIs.Variable.
Examples
A minimal example defining a variable and using it in an expression.
using uCalcSoftware;
var uc = new uCalc();
uc.DefineVariable("x = 10");
Console.WriteLine(uc.Eval("x * 5"));
50 using uCalcSoftware; var uc = new uCalc(); uc.DefineVariable("x = 10"); Console.WriteLine(uc.Eval("x * 5"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineVariable("x = 10");
cout << uc.Eval("x * 5") << endl;
}
50 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineVariable("x = 10"); cout << uc.Eval("x * 5") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x = 10")
Console.WriteLine(uc.Eval("x * 5"))
End Sub
End Module
50 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x = 10") Console.WriteLine(uc.Eval("x * 5")) End Sub End Module
Defines variables with explicit types, inferred types, and default types.
using uCalcSoftware;
var uc = new uCalc();
// Explicit type definition
uc.DefineVariable("explicitInt As Int = 123");
// Type inferred from the initial string value
uc.DefineVariable("inferredStr = 'hello'");
// Type defaults to Double as no type or value is given
var defaultVar = uc.DefineVariable("defaultVar");
Console.WriteLine($"explicitInt type: {uc.ItemOf("explicitInt").DataType.Name}");
Console.WriteLine($"inferredStr type: {uc.ItemOf("inferredStr").DataType.Name}");
Console.WriteLine($"defaultVar type: {defaultVar.DataType.Name}");
explicitInt type: int
inferredStr type: string
defaultVar type: double using uCalcSoftware; var uc = new uCalc(); // Explicit type definition uc.DefineVariable("explicitInt As Int = 123"); // Type inferred from the initial string value uc.DefineVariable("inferredStr = 'hello'"); // Type defaults to Double as no type or value is given var defaultVar = uc.DefineVariable("defaultVar"); Console.WriteLine($"explicitInt type: {uc.ItemOf("explicitInt").DataType.Name}"); Console.WriteLine($"inferredStr type: {uc.ItemOf("inferredStr").DataType.Name}"); Console.WriteLine($"defaultVar type: {defaultVar.DataType.Name}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Explicit type definition
uc.DefineVariable("explicitInt As Int = 123");
// Type inferred from the initial string value
uc.DefineVariable("inferredStr = 'hello'");
// Type defaults to Double as no type or value is given
auto defaultVar = uc.DefineVariable("defaultVar");
cout << "explicitInt type: " << uc.ItemOf("explicitInt").DataType().Name() << endl;
cout << "inferredStr type: " << uc.ItemOf("inferredStr").DataType().Name() << endl;
cout << "defaultVar type: " << defaultVar.DataType().Name() << endl;
}
explicitInt type: int
inferredStr type: string
defaultVar type: double #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Explicit type definition uc.DefineVariable("explicitInt As Int = 123"); // Type inferred from the initial string value uc.DefineVariable("inferredStr = 'hello'"); // Type defaults to Double as no type or value is given auto defaultVar = uc.DefineVariable("defaultVar"); cout << "explicitInt type: " << uc.ItemOf("explicitInt").DataType().Name() << endl; cout << "inferredStr type: " << uc.ItemOf("inferredStr").DataType().Name() << endl; cout << "defaultVar type: " << defaultVar.DataType().Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Explicit type definition
uc.DefineVariable("explicitInt As Int = 123")
'// Type inferred from the initial string value
uc.DefineVariable("inferredStr = 'hello'")
'// Type defaults to Double as no type or value is given
Dim defaultVar = uc.DefineVariable("defaultVar")
Console.WriteLine($"explicitInt type: {uc.ItemOf("explicitInt").DataType.Name}")
Console.WriteLine($"inferredStr type: {uc.ItemOf("inferredStr").DataType.Name}")
Console.WriteLine($"defaultVar type: {defaultVar.DataType.Name}")
End Sub
End Module
explicitInt type: int
inferredStr type: string
defaultVar type: double Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Explicit type definition uc.DefineVariable("explicitInt As Int = 123") '// Type inferred from the initial string value uc.DefineVariable("inferredStr = 'hello'") '// Type defaults to Double as no type or value is given Dim defaultVar = uc.DefineVariable("defaultVar") Console.WriteLine($"explicitInt type: {uc.ItemOf("explicitInt").DataType.Name}") Console.WriteLine($"inferredStr type: {uc.ItemOf("inferredStr").DataType.Name}") Console.WriteLine($"defaultVar type: {defaultVar.DataType.Name}") End Sub End Module
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
DefineVariable; using pointers
using uCalcSoftware;
var uc = new uCalc();
var Int8Var = uc.DefineVariable("x As Int8 = -1");
var Int16Var = uc.DefineVariable("y As Int16 = -1");
var StrVar = uc.DefineVariable("MyStr = 'Hello there'");
Console.WriteLine(uc.EvalStr("x"));
Console.WriteLine(uc.EvalStr("y"));
Console.WriteLine(uc.EvalStr("MyStr"));
var xPtr = uc.DefineVariable("xPtr As Pointer"); // General pointer
var yPtr = uc.DefineVariable("yPtr As Int16u Ptr"); // pointer specific to unsigned Int16
var yPtrB = uc.DefineVariable("yPtrB As Int16 Ptr = AddressOf(y)"); // Using AddressOf
var StrPtr = uc.DefineVariable("StrPtr As String Ptr");
xPtr.ValuePtr(Int8Var.ValueAddr()); // Sets the pointer address
yPtr.ValuePtr(Int16Var.ValueAddr()); // Note: address of signed Int16 going to an unsigned Ptr
StrPtr.ValuePtr(StrVar.ValueAddr());
// Note: for the ints we are now returning unsigned values; so -1 turns into positive numbers
Console.WriteLine(uc.EvalStr("ValueAt(Int8u, xPtr)")); // Type required because it's defined as generar pointer
Console.WriteLine(uc.EvalStr("ValueAt(yPtr)")); // Type name not needed because it's defined as Int16u Ptr
Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)"));
Console.WriteLine(uc.EvalStr("ValueAt(StrPtr)"));
// Iterate through uc.ItemOf(ItemIs.DataType, n).Name()
// to see data type names you can use with ValueAt
var OtherInt = uc.DefineVariable("OtherInt As Int16 = 1234");
uc.DataTypeOf(BuiltInType.Integer_16).SetScalar(Int16Var.ValueAddr(), OtherInt.ValueAddr());
Console.WriteLine(uc.EvalStr("OtherInt"));
Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)"));
-1
-1
Hello there
255
65535
-1
Hello there
1234
1234 using uCalcSoftware; var uc = new uCalc(); var Int8Var = uc.DefineVariable("x As Int8 = -1"); var Int16Var = uc.DefineVariable("y As Int16 = -1"); var StrVar = uc.DefineVariable("MyStr = 'Hello there'"); Console.WriteLine(uc.EvalStr("x")); Console.WriteLine(uc.EvalStr("y")); Console.WriteLine(uc.EvalStr("MyStr")); var xPtr = uc.DefineVariable("xPtr As Pointer"); // General pointer var yPtr = uc.DefineVariable("yPtr As Int16u Ptr"); // pointer specific to unsigned Int16 var yPtrB = uc.DefineVariable("yPtrB As Int16 Ptr = AddressOf(y)"); // Using AddressOf var StrPtr = uc.DefineVariable("StrPtr As String Ptr"); xPtr.ValuePtr(Int8Var.ValueAddr()); // Sets the pointer address yPtr.ValuePtr(Int16Var.ValueAddr()); // Note: address of signed Int16 going to an unsigned Ptr StrPtr.ValuePtr(StrVar.ValueAddr()); // Note: for the ints we are now returning unsigned values; so -1 turns into positive numbers Console.WriteLine(uc.EvalStr("ValueAt(Int8u, xPtr)")); // Type required because it's defined as generar pointer Console.WriteLine(uc.EvalStr("ValueAt(yPtr)")); // Type name not needed because it's defined as Int16u Ptr Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)")); Console.WriteLine(uc.EvalStr("ValueAt(StrPtr)")); // Iterate through uc.ItemOf(ItemIs.DataType, n).Name() // to see data type names you can use with ValueAt var OtherInt = uc.DefineVariable("OtherInt As Int16 = 1234"); uc.DataTypeOf(BuiltInType.Integer_16).SetScalar(Int16Var.ValueAddr(), OtherInt.ValueAddr()); Console.WriteLine(uc.EvalStr("OtherInt")); Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto Int8Var = uc.DefineVariable("x As Int8 = -1");
auto Int16Var = uc.DefineVariable("y As Int16 = -1");
auto StrVar = uc.DefineVariable("MyStr = 'Hello there'");
cout << uc.EvalStr("x") << endl;
cout << uc.EvalStr("y") << endl;
cout << uc.EvalStr("MyStr") << endl;
auto xPtr = uc.DefineVariable("xPtr As Pointer"); // General pointer
auto yPtr = uc.DefineVariable("yPtr As Int16u Ptr"); // pointer specific to unsigned Int16
auto yPtrB = uc.DefineVariable("yPtrB As Int16 Ptr = AddressOf(y)"); // Using AddressOf
auto StrPtr = uc.DefineVariable("StrPtr As String Ptr");
xPtr.ValuePtr(Int8Var.ValueAddr()); // Sets the pointer address
yPtr.ValuePtr(Int16Var.ValueAddr()); // Note: address of signed Int16 going to an unsigned Ptr
StrPtr.ValuePtr(StrVar.ValueAddr());
// Note: for the ints we are now returning unsigned values; so -1 turns into positive numbers
cout << uc.EvalStr("ValueAt(Int8u, xPtr)") << endl; // Type required because it's defined as generar pointer
cout << uc.EvalStr("ValueAt(yPtr)") << endl; // Type name not needed because it's defined as Int16u Ptr
cout << uc.EvalStr("ValueAt(yPtrB)") << endl;
cout << uc.EvalStr("ValueAt(StrPtr)") << endl;
// Iterate through uc.ItemOf(ItemIs.DataType, n).Name()
// to see data type names you can use with ValueAt
auto OtherInt = uc.DefineVariable("OtherInt As Int16 = 1234");
uc.DataTypeOf(BuiltInType::Integer_16).SetScalar(Int16Var.ValueAddr(), OtherInt.ValueAddr());
cout << uc.EvalStr("OtherInt") << endl;
cout << uc.EvalStr("ValueAt(yPtrB)") << endl;
}
-1
-1
Hello there
255
65535
-1
Hello there
1234
1234 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto Int8Var = uc.DefineVariable("x As Int8 = -1"); auto Int16Var = uc.DefineVariable("y As Int16 = -1"); auto StrVar = uc.DefineVariable("MyStr = 'Hello there'"); cout << uc.EvalStr("x") << endl; cout << uc.EvalStr("y") << endl; cout << uc.EvalStr("MyStr") << endl; auto xPtr = uc.DefineVariable("xPtr As Pointer"); // General pointer auto yPtr = uc.DefineVariable("yPtr As Int16u Ptr"); // pointer specific to unsigned Int16 auto yPtrB = uc.DefineVariable("yPtrB As Int16 Ptr = AddressOf(y)"); // Using AddressOf auto StrPtr = uc.DefineVariable("StrPtr As String Ptr"); xPtr.ValuePtr(Int8Var.ValueAddr()); // Sets the pointer address yPtr.ValuePtr(Int16Var.ValueAddr()); // Note: address of signed Int16 going to an unsigned Ptr StrPtr.ValuePtr(StrVar.ValueAddr()); // Note: for the ints we are now returning unsigned values; so -1 turns into positive numbers cout << uc.EvalStr("ValueAt(Int8u, xPtr)") << endl; // Type required because it's defined as generar pointer cout << uc.EvalStr("ValueAt(yPtr)") << endl; // Type name not needed because it's defined as Int16u Ptr cout << uc.EvalStr("ValueAt(yPtrB)") << endl; cout << uc.EvalStr("ValueAt(StrPtr)") << endl; // Iterate through uc.ItemOf(ItemIs.DataType, n).Name() // to see data type names you can use with ValueAt auto OtherInt = uc.DefineVariable("OtherInt As Int16 = 1234"); uc.DataTypeOf(BuiltInType::Integer_16).SetScalar(Int16Var.ValueAddr(), OtherInt.ValueAddr()); cout << uc.EvalStr("OtherInt") << endl; cout << uc.EvalStr("ValueAt(yPtrB)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim Int8Var = uc.DefineVariable("x As Int8 = -1")
Dim Int16Var = uc.DefineVariable("y As Int16 = -1")
Dim StrVar = uc.DefineVariable("MyStr = 'Hello there'")
Console.WriteLine(uc.EvalStr("x"))
Console.WriteLine(uc.EvalStr("y"))
Console.WriteLine(uc.EvalStr("MyStr"))
Dim xPtr = uc.DefineVariable("xPtr As Pointer") '// General pointer
Dim yPtr = uc.DefineVariable("yPtr As Int16u Ptr") '// pointer specific to unsigned Int16
Dim yPtrB = uc.DefineVariable("yPtrB As Int16 Ptr = AddressOf(y)") '// Using AddressOf
Dim StrPtr = uc.DefineVariable("StrPtr As String Ptr")
xPtr.ValuePtr(Int8Var.ValueAddr()) '// Sets the pointer address
yPtr.ValuePtr(Int16Var.ValueAddr()) '// Note: address of signed Int16 going to an unsigned Ptr
StrPtr.ValuePtr(StrVar.ValueAddr())
'// Note: for the ints we are now returning unsigned values; so -1 turns into positive numbers
Console.WriteLine(uc.EvalStr("ValueAt(Int8u, xPtr)")) '// Type required because it's defined as generar pointer
Console.WriteLine(uc.EvalStr("ValueAt(yPtr)")) '// Type name not needed because it's defined as Int16u Ptr
Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)"))
Console.WriteLine(uc.EvalStr("ValueAt(StrPtr)"))
'// Iterate through uc.ItemOf(ItemIs.DataType, n).Name()
'// to see data type names you can use with ValueAt
Dim OtherInt = uc.DefineVariable("OtherInt As Int16 = 1234")
uc.DataTypeOf(BuiltInType.Integer_16).SetScalar(Int16Var.ValueAddr(), OtherInt.ValueAddr())
Console.WriteLine(uc.EvalStr("OtherInt"))
Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)"))
End Sub
End Module
-1
-1
Hello there
255
65535
-1
Hello there
1234
1234 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim Int8Var = uc.DefineVariable("x As Int8 = -1") Dim Int16Var = uc.DefineVariable("y As Int16 = -1") Dim StrVar = uc.DefineVariable("MyStr = 'Hello there'") Console.WriteLine(uc.EvalStr("x")) Console.WriteLine(uc.EvalStr("y")) Console.WriteLine(uc.EvalStr("MyStr")) Dim xPtr = uc.DefineVariable("xPtr As Pointer") '// General pointer Dim yPtr = uc.DefineVariable("yPtr As Int16u Ptr") '// pointer specific to unsigned Int16 Dim yPtrB = uc.DefineVariable("yPtrB As Int16 Ptr = AddressOf(y)") '// Using AddressOf Dim StrPtr = uc.DefineVariable("StrPtr As String Ptr") xPtr.ValuePtr(Int8Var.ValueAddr()) '// Sets the pointer address yPtr.ValuePtr(Int16Var.ValueAddr()) '// Note: address of signed Int16 going to an unsigned Ptr StrPtr.ValuePtr(StrVar.ValueAddr()) '// Note: for the ints we are now returning unsigned values; so -1 turns into positive numbers Console.WriteLine(uc.EvalStr("ValueAt(Int8u, xPtr)")) '// Type required because it's defined as generar pointer Console.WriteLine(uc.EvalStr("ValueAt(yPtr)")) '// Type name not needed because it's defined as Int16u Ptr Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)")) Console.WriteLine(uc.EvalStr("ValueAt(StrPtr)")) '// Iterate through uc.ItemOf(ItemIs.DataType, n).Name() '// to see data type names you can use with ValueAt Dim OtherInt = uc.DefineVariable("OtherInt As Int16 = 1234") uc.DataTypeOf(BuiltInType.Integer_16).SetScalar(Int16Var.ValueAddr(), OtherInt.ValueAddr()) Console.WriteLine(uc.EvalStr("OtherInt")) Console.WriteLine(uc.EvalStr("ValueAt(yPtrB)")) End Sub End Module
Arrays with DefineVariable
using uCalcSoftware;
var uc = new uCalc();
var MyArray = uc.DefineVariable("MyArray[3]");
uc.DefineVariable("MyArrayStr[] = {'aa', 'bb', 'cc'}");
uc.Eval("MyArray[0] = 111; MyArray[1] = 222; MyArray[2] = 333");
Console.WriteLine(uc.EvalStr("MyArray[0]"));
Console.WriteLine(uc.EvalStr("MyArray[1]"));
Console.WriteLine(uc.EvalStr("MyArray[2]"));
Console.WriteLine(uc.EvalStr("MyArrayStr[0]"));
Console.WriteLine(uc.EvalStr("MyArrayStr[1]"));
Console.WriteLine(uc.EvalStr("MyArrayStr[2]"));
Console.WriteLine(MyArray.Count);
Console.WriteLine(uc.ItemOf("MyArrayStr").Count);
111
222
333
aa
bb
cc
3
3 using uCalcSoftware; var uc = new uCalc(); var MyArray = uc.DefineVariable("MyArray[3]"); uc.DefineVariable("MyArrayStr[] = {'aa', 'bb', 'cc'}"); uc.Eval("MyArray[0] = 111; MyArray[1] = 222; MyArray[2] = 333"); Console.WriteLine(uc.EvalStr("MyArray[0]")); Console.WriteLine(uc.EvalStr("MyArray[1]")); Console.WriteLine(uc.EvalStr("MyArray[2]")); Console.WriteLine(uc.EvalStr("MyArrayStr[0]")); Console.WriteLine(uc.EvalStr("MyArrayStr[1]")); Console.WriteLine(uc.EvalStr("MyArrayStr[2]")); Console.WriteLine(MyArray.Count); Console.WriteLine(uc.ItemOf("MyArrayStr").Count);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto MyArray = uc.DefineVariable("MyArray[3]");
uc.DefineVariable("MyArrayStr[] = {'aa', 'bb', 'cc'}");
uc.Eval("MyArray[0] = 111; MyArray[1] = 222; MyArray[2] = 333");
cout << uc.EvalStr("MyArray[0]") << endl;
cout << uc.EvalStr("MyArray[1]") << endl;
cout << uc.EvalStr("MyArray[2]") << endl;
cout << uc.EvalStr("MyArrayStr[0]") << endl;
cout << uc.EvalStr("MyArrayStr[1]") << endl;
cout << uc.EvalStr("MyArrayStr[2]") << endl;
cout << MyArray.Count() << endl;
cout << uc.ItemOf("MyArrayStr").Count() << endl;
}
111
222
333
aa
bb
cc
3
3 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto MyArray = uc.DefineVariable("MyArray[3]"); uc.DefineVariable("MyArrayStr[] = {'aa', 'bb', 'cc'}"); uc.Eval("MyArray[0] = 111; MyArray[1] = 222; MyArray[2] = 333"); cout << uc.EvalStr("MyArray[0]") << endl; cout << uc.EvalStr("MyArray[1]") << endl; cout << uc.EvalStr("MyArray[2]") << endl; cout << uc.EvalStr("MyArrayStr[0]") << endl; cout << uc.EvalStr("MyArrayStr[1]") << endl; cout << uc.EvalStr("MyArrayStr[2]") << endl; cout << MyArray.Count() << endl; cout << uc.ItemOf("MyArrayStr").Count() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim MyArray = uc.DefineVariable("MyArray[3]")
uc.DefineVariable("MyArrayStr[] = {'aa', 'bb', 'cc'}")
uc.Eval("MyArray[0] = 111; MyArray[1] = 222; MyArray[2] = 333")
Console.WriteLine(uc.EvalStr("MyArray[0]"))
Console.WriteLine(uc.EvalStr("MyArray[1]"))
Console.WriteLine(uc.EvalStr("MyArray[2]"))
Console.WriteLine(uc.EvalStr("MyArrayStr[0]"))
Console.WriteLine(uc.EvalStr("MyArrayStr[1]"))
Console.WriteLine(uc.EvalStr("MyArrayStr[2]"))
Console.WriteLine(MyArray.Count)
Console.WriteLine(uc.ItemOf("MyArrayStr").Count)
End Sub
End Module
111
222
333
aa
bb
cc
3
3 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim MyArray = uc.DefineVariable("MyArray[3]") uc.DefineVariable("MyArrayStr[] = {'aa', 'bb', 'cc'}") uc.Eval("MyArray[0] = 111; MyArray[1] = 222; MyArray[2] = 333") Console.WriteLine(uc.EvalStr("MyArray[0]")) Console.WriteLine(uc.EvalStr("MyArray[1]")) Console.WriteLine(uc.EvalStr("MyArray[2]")) Console.WriteLine(uc.EvalStr("MyArrayStr[0]")) Console.WriteLine(uc.EvalStr("MyArrayStr[1]")) Console.WriteLine(uc.EvalStr("MyArrayStr[2]")) Console.WriteLine(MyArray.Count) Console.WriteLine(uc.ItemOf("MyArrayStr").Count) End Sub End Module