数据表值的数学表达式

时间:2021-02-24 15:18:36

标签: vb.net datatable expression calculation ncalc

我有以下数据:

Device Time               Value1    Value2
1      24.02.2021 16:03   15        17
2      24.02.2021 16:03   4         26
1      24.02.2021 16:04   16        17

我会让用户能够使用给定的数据进行数学计算。 例如:[设备 1] + [设备 2] 或 [设备 1] * 2 - [设备 2]

目前我正在使用 ncalc 来解释计算这个表达式。

For each curItem in timeList
  calcstring = "[G1]" 'Example UserInput
  Dim ex As New Expression(calcstring)
  
  For each dev As Integer in deviceList 'In this example to List would only have Device "1"
    ex.Parameters("G" & dev) = (From t in ds.tblSample Where t.Device = dev AndAlso t.Time = curItem Select If(t.IsValue1Null, 0, t.Value1)).FirstOrDefault
  Next
  Dim dr As New Datarow
  dr(2) = ex.Evaluate
  ... 'Same for Value2
Next

这段代码不仅看起来很慢,而且很慢。难以置信的慢。我还有其他选择吗?

0 个答案:

没有答案