参考代码
MainTable = Tables("统计")
Dim wlbm As String = "17475000011232"
e.Form.Controls("Label1").Text = "正在处理数据..."
Application.DoEvents()
Dim drs = DataTables("sum").Select("物料编码='" & wlbm & "' and 日期时间 <= #" & Date.Today.AddDays(3) & "# and 日期时间 > #" & Date.Today & "# ", "日期时间")
Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
p.Maximum = drs.Count '设置最大值
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
DataTables("统计").ResumeRedraw
DataTables("统计").StopRedraw
Dim st As Date = Date.Now '将开始时间保存在变量st中
Dim sum = DataTables("sum").compute("sum(需求数量)", "物料编码='" & wlbm & "' and 日期时间 <= #" & Date.Today & "#")
For Each dr As DataRow In drs
Dim dr1 As DataRow = DataTables("统计").AddNew()
dr1("物料编码") = dr("物料编码")
dr1("日期时间") = dr("日期时间")
Dim temp As Double = sum
For Each dr2 As DataRow In drs
If dr2("日期时间") <= dr1("日期时间") Then
temp += dr2("需求数量")
Else
Exit For
End If
Next
dr1("在此之前的需求数量") = temp
p.Value += 1 '当前值为已经完成的行数
Next
DataTables("统计").ResumeRedraw
If DataTables("统计").HasChanges Then
'DataTables("统计").save
End If
e.Form.Controls("Label1").Text = " 更新完毕."
MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒") '计算并显示执行代码所花费的秒数