Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// This example is mainly meant for C++ where it works with ordinary scalar variables '// See the other example where we work with a uCalc array '// 1. Use an array so the data lives on the heap as a reference type '// Boxing is used for scalar variables; a boxed copy of the scalar disconnected from the uCalc '// variable would prevent the example from working as expected. '// You technically can get around this with the C# "unsafe" directive, but it's not recommended Dim myHostVar() As Double = { 1234.5 } '// 2. Pin the array Dim myHostVarHandle = System.Runtime.InteropServices.GCHandle.Alloc(myHostVar, System.Runtime.InteropServices.GCHandleType.Pinned) '// 3. Bind the uCalc variable to the pinned memory address uc.DefineVariable("myVar", myHostVarHandle.AddrOfPinnedObject()) Console.WriteLine(uc.Eval("myVar")) '// Output: 1234.5 '// Changing the uCalc variable updates the pinned array uc.Eval("myVar = 456") '// The change is reflected in the C# array Console.WriteLine(myHostVar(0)) '// Output: 456 '// Changing the C# array updates uCalc myHostVar(0) = 9876 Console.WriteLine(uc.Eval("myVar")) '// Output: 9876 '// Fast Parse & Evaluate loop Dim expr = uc.Parse("myVar * 10") For myHostVar(0) = 1 To 5 Console.WriteLine(expr.Evaluate()) Next '// Don't forget to free the handle when you are completely done with the parser instance myHostVarHandle.Free() End Sub End Module