Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyIIf(ByVal cb As uCalc.Callback)
      Dim condition = cb.ArgBool(1)
      Dim thenPart = cb.ArgExpr(2)
      Dim elsePart = cb.ArgExpr(3)
      
      If condition Then
         cb.Return(thenPart.Evaluate())
      Else
         cb.Return(elsePart.Evaluate())
      End If
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineFunction("MyIIf(cond As Bool, ByExpr thenExpr, ByExpr elseExpr)", AddressOf MyIIf)
      
      '// The 'else' branch contains 1/0, but since the condition is true,
      '// it is never evaluated.
      Console.WriteLine(uc.Eval("MyIIf(10 > 5, 100, 1/0)"))
      
      '// The 'then' branch contains 1/0, but it is never evaluated.
      Console.WriteLine(uc.Eval("MyIIf(10 < 5, 1/0, 200)"))
   End Sub
End Module