2

What is the equivalent code for creating a custom function in vb2010 instead of c#?

  Expression e = new Expression("SecretOperation(3, 6)");
  e.EvaluateFunction += delegate(string name, FunctionArgs args)
      {
          if (name == "SecretOperation")
              args.Result = (int)args.Parameters[0].Evaluate() + (int)args.Parameters[1].Evaluate();
      };

1 Answers1

4

Here's how to do it !

Imports NCalc

Public Class Form1
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim exp As New Expression("SecretOperation(3, 6)")
      AddHandler exp.EvaluateFunction, Sub(str, args)
      If str = "SecretOperation" Then
        args.Result = CInt(args.Parameters(0).Evaluate() + args.Parameters(1).Evaluate())
      End If
    End Sub
  End Sub
End Class

From documentation : http://msdn.microsoft.com/en-us/library/ms172879.aspx

Atiris
  • 2,613
  • 2
  • 28
  • 42
aybe
  • 15,516
  • 9
  • 57
  • 105