或者:
Dim d1 As Date
Dim d2 As Date
Dim nms() As String = {"本日销量","本周销量","本旬销量","本月销量","本年销量"}
For Each dr As DataRow In DataTables("日报表").DataRows
For Each nm As String In nms
Select Case nm
Case "本日销量"
d1 = Date.Today
d2 = Date.Today
Case "本周销量"
Dim n As Integer = Date.Today.DayOfWeek
d1 = Date.Today.AddDays(-n)
d2 = Date.Today.AddDays(6-n)
Case "本旬销量"
Dim n As Integer = Date.Today.Day
Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month
Select n
Case 1 To 10
d1 = new Date(y,m,1)
d2 = new Date(y,m,10)
Case 11 To 20
d1 = new Date(y,m,11)
d2 = new Date(y,m,20)
Case Else
d1 = new Date(y,m,21)
d2 = new Date(y,m,Date.DaysInMonth(y,m))
End Select
Case "本月销量"
Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month
d1 = New Date(y,m,1)
d2 = new Date(y,m,Date.DaysInMonth(y,m))
Case "本年销量"
Dim y As Integer = Date.Today.Year
d1 = New Date(y,1,1)
d2 = new Date(y,12,Date.DaysInMonth(y,12))
End Select
Dim f As String = "销售日期 >= #" & d1 & "# And 销售日期 <= #" & d2 & "#"
dr(nm) = DataTables("销售表").Compute("sum(数量)","产品 = '" & dr("产品") & "' And " & f)
Next
Next