简体   繁体   English

自定义函数的NCalc表达式评估错误

[英]NCalc expression evaluation error for custom function

I have an expression which has all calls to all custom functions. 我有一个表达式,它具有对所有自定义函数的所有调用。

IIF(FVAL(DES_CODE)=1039 OR FVAL(DES_CODE)=1040 OR FVAL(DES_CODE)=1034,0,TBLEVA(PTAX, FVAL(HOPO_GRS)))

When trying to evaluate this expression the NCalc engine is producing an error. 在尝试评估此表达式时, NCalc引擎产生错误。 I'm not able to figure out why. 我无法弄清楚原因。 All function declared in the expression has been handled in the EvalFunction event of the expression. 表达式中声明的所有函数都已在表达式的EvalFunction事件中处理。 Then why is this error arising? 那为什么会出现这个错误呢?

mismatched input 'OR' expecting ')' at line 1:24 missing EOF at 'OR' at line 1:47

CODE - 代码 -

This is where I'm initializing the expression engine. 这是我正在初始化表达式引擎的地方。

Dim exp As New Expression(vbCode, EvaluateOptions.IgnoreCase)
AddHandler exp.EvaluateParameter, AddressOf EvalParameters
AddHandler exp.EvaluateFunction, AddressOf EvalFunction
xReturn = Convert.ToDecimal(exp.Evaluate())

These are the events for the expression. 这些是表达式的事件。

Public Sub EvalFunction(ByVal name As String, ByVal args As FunctionArgs)
    Select Case name.ToUpper.Trim
        Case "FVAL"
            Dim xobj = args.EvaluateParameters()
            args.Result = fc.Fval(xobj(0))
        Case "ORIGINALVAL"
            Dim xobj = args.EvaluateParameters()
            args.Result = fc.ORIGINALVAL(xobj(0))
        Case "IIF"
            Dim xobj = args.EvaluateParameters()
            args.Result = fc.IIF(xobj(0), xobj(1), xobj(2))
        Case "LOANDEDUCT"
            Dim xobj = args.EvaluateParameters()
            args.Result = fc.LOANDEDUCT(xobj(0))
        Case "TBLEVA"
            Dim xobj = args.EvaluateParameters()
            args.Result = fc.TBLEVA(xobj(0), xobj(1))
        Case "PERIODMONTH"
            args.Result = fc.PERIODMONTH()
        Case "PERIODSTART"
            args.Result = fc.PERIODSTART()
        Case "AGE"
            Dim xobj = args.EvaluateParameters()
            args.Result = fc.Age(xobj(0))
        Case "INT"
            Dim xobj = args.EvaluateParameters()
            args.Result = fc.Age(xobj(0))
    End Select
End Sub
Public Sub EvalParameters(ByVal name As String, ByVal args As ParameterArgs)
    args.Result = name
End Sub

Just replace OR s with || 只需用||替换OR or or (lowercase) or (小写)

IIF(FVAL(DES_CODE)=1039 || FVAL(DES_CODE)=1040 || FVAL(DES_CODE)=1034,0,TBLEVA(PTAX, FVAL(HOPO_GRS)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM