Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Original default instance
      uCalc.DefaultInstance.DefineVariable("id = 'Original'")
      Console.WriteLine($"Current Default ID: {uCalc.DefaultInstance.EvalStr("id")}")
      
      '// Push a new default instance onto the stack
      Dim ucA As New uCalc()
      ucA.DefineVariable("id = 'Instance A'")
      ucA.IsDefault = true
      Console.WriteLine($"Current Default ID: {uCalc.DefaultInstance.EvalStr("id")}")
      
      '// The 'NewUsing' block creates a temporary, scoped default instance
      
      '// The following instance will be auto-released at the end of the block
      Using ucB As New uCalc()
         ucB.DefineVariable("id = 'Instance B (temp)'")
         ucB.IsDefault = true '// Pushes 'ucB' onto the stack
         Console.WriteLine($"Current Default ID: {uCalc.DefaultInstance.EvalStr("id")}")
      End Using
      
      '// 'ucB' has gone out of scope, so the default reverts to the previous one ('ucA')
      Console.WriteLine($"Current Default ID (after scope exit): {uCalc.DefaultInstance.EvalStr("id")}")
      
      '// Manually unset 'ucA'
      ucA.IsDefault = false
      Console.WriteLine($"Current Default ID (after unset): {uCalc.DefaultInstance.EvalStr("id")}")
   End Sub
End Module