A practical example showing how to manage two separate uCalc instances with conflicting variable names.

ID: 681

				
					using uCalcSoftware;

var uc = new uCalc();
// Create two independent uCalc instances
var uc1 = new uCalc();
var uc2 = new uCalc();

// Define a variable 'x' in each instance with a different value
var itemX1 = uc1.DefineVariable("x = 100");
var itemX2 = uc2.DefineVariable("x = 200");

// Use the item to get its parent context and evaluate 'x * 2'
// This correctly uses uc1's context where x is 100.
Console.WriteLine($"Context 1: {itemX1.uCalc.Eval("x * 2")}");

// This correctly uses uc2's context where x is 200.
Console.WriteLine($"Context 2: {itemX2.uCalc.Eval("x * 2")}");

// Clean up the instances
uc1.Release();
uc2.Release();
				
			
Context 1: 200
Context 2: 400
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Create two independent uCalc instances
   uCalc uc1;
   uCalc uc2;

   // Define a variable 'x' in each instance with a different value
   auto itemX1 = uc1.DefineVariable("x = 100");
   auto itemX2 = uc2.DefineVariable("x = 200");

   // Use the item to get its parent context and evaluate 'x * 2'
   // This correctly uses uc1's context where x is 100.
   cout << "Context 1: " << itemX1.uCalc().Eval("x * 2") << endl;

   // This correctly uses uc2's context where x is 200.
   cout << "Context 2: " << itemX2.uCalc().Eval("x * 2") << endl;

   // Clean up the instances
   uc1.Release();
   uc2.Release();
}
				
			
Context 1: 200
Context 2: 400
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Create two independent uCalc instances
      Dim uc1 As New uCalc()
      Dim uc2 As New uCalc()
      
      '// Define a variable 'x' in each instance with a different value
      Dim itemX1 = uc1.DefineVariable("x = 100")
      Dim itemX2 = uc2.DefineVariable("x = 200")
      
      '// Use the item to get its parent context and evaluate 'x * 2'
      '// This correctly uses uc1's context where x is 100.
      Console.WriteLine($"Context 1: {itemX1.uCalc.Eval("x * 2")}")
      
      '// This correctly uses uc2's context where x is 200.
      Console.WriteLine($"Context 2: {itemX2.uCalc.Eval("x * 2")}")
      
      '// Clean up the instances
      uc1.Release()
      uc2.Release()
   End Sub
End Module
				
			
Context 1: 200
Context 2: 400