在命令窗口测试的代码如下:Dim aa As Integer = CurrentTable.Position
Dim bb As String = Tables("原材料出库表").Rows(aa)("物料名称")
Dim cc As String = Tables("原材料出库表").Rows(aa)("领用日期")
output.show(bb)
output.show(cc)
Dim sum1 As Double = DataTables("原材料入库表").Compute("Sum(数量)", "物料名称 = '"& bb &"' and 日期 <= #"& cc &"# ")
Dim sum2 As Double = DataTables("原材料入库表").Compute("Sum(金额)", "物料名称 = '"& bb &"' and 日期 <= #"& cc &"# ")
output.show(sum1)
output.show(sum2)
Dim sum3 As Double = sum2 / sum1
output.show(sum3)
结果:
烧饼
2017-10-15
20
54
2.7
放到表事件后,计算的条件表达式里的bb和cc改成了新值zf1 和zf2后的代码:
Dim co1 As DataCol = e.DataCol
Dim dr As DataRow = e.DataRow
Select Case co1.Name
Case "领用日期","物料代码"
If dr.IsNull("物料代码") OrElse dr.IsNull("领用日期") Then '如果数量或单价为空
dr("数量") = Nothing
dr("单价") = Nothing
dr("金额") = Nothing
Else
Dim zf1 As String = e.NewValue
Dim zf2 As String = e.NewValue
zf1 = dr("物料代码")
zf2 = dr("领用日期")
Dim sum1 As Double = DataTables("原材料入库表").Compute("Sum(数量)", "物料名称 = '"& zf1 &"' and 日期 <= #"& zf2 &"# ")
Dim sum2 As Double = DataTables("原材料入库表").Compute("Sum(金额)", "物料名称 = '"& zf1 &"' and 日期 <= #"& zf2 &"# ")
Messagebox.Show(sum1)
Messagebox.Show(sum2)
Dim sum3 As Double = sum2 / sum1
dr("单价") = sum3
Messagebox.Show(sum3)
End If
End Select
运行后sum1和sum2没计算出结果,全是0。
请老师给看下这段代码吧,谢谢!!!!