If e.DataRow.IsNull("费用计算式") = False Then
Dim str As String = e.DataRow("费用计算式")
Dim dr As DataRow
Dim pattern As String = "{.+?}"
Dim rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
For Each match As System.Text.RegularExpressions.Match In rgx.Matches(str)
dr = e.DataTable.Find("序号='" & match.Value.trim("{","}") & "'")
If dr IsNot Nothing Then
str = str.replace(match.Value, dr("金额"))
End If
Next
pattern = "\[.+?\]"
rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
For Each match As System.Text.RegularExpressions.Match In rgx.Matches(str)
str = str.replace(match.Value, e.DataRow(match.Value.trim("[","]")))
Next
If TryEval(str, e.DataRow) Then
e.DataRow("金额") = Eval2(str,e.DataRow)
Else
msgbox("公式错误")
End If
End If
[此贴子已经被作者于2017/9/28 15:38:42编辑过]