前辈帮我看看这个代码应该怎么优化
Dim y As Integer = Date.Today.Year
Dim sy As Integer = (y-1)
Dim sy1 As New Date(sy, 1, 1)
Dim sy2 As New Date(sy, 12, 31)
Dim y1 As New Date(y, 1, 1)
Dim y2 As New Date(y, 12, 31)
Dim q As Integer = (Date.Today.Month - 1) \ 3 + 1 '计算现在是第几个季度Dim dt1 As New Date(y, 3 * (q - 1) + 1, 1) '获取本季度的第一天
Dim q1 As New Date(y, 3 * (q - 1) + 1, 1) '获取本季度的第一天
Dim q2 As New Date(y, 3 * q, Date.DaysInMonth(2011,3 * q)) '获取本季度的最后一天
Dim m As Integer = Date.Today.Month
Dim m1 As New Date(y, m, 1)
Dim m2 As New Date(y, m, Date.DaysInMonth(y, m)) '获取本月的最后一天
Dim w As Integer = Date.Today.DayOfWeek '算出今天是星期几
Dim dt1 As Date = Date.Today.AddDays(-w) '获取本周的第一天
Dim dt2 As Date = Date.Today.AddDays(6 - w) '获取本周的最后一天
Dim Filter As String
If txt = "当天" Then
Filter = "录入日期 >= #" & dt1 & "# And 录入日期 <= #" & dt1 & "#"
tbl.Filter = Filter
End If
If txt = "本周" Then
Filter = "录入日期 >= #" & dt1 & "# And 录入日期 <= #" & dt2 & "#"
tbl.Filter = Filter
End If
If txt = "本月" Then
Filter = "录入日期 >= #" & m1 & "# And 录入日期 <= #" & m2 & "#"
tbl.Filter = Filter
End If
If txt = "本季度" Then
Filter = "录入日期 >= #" & q1 & "# And 录入日期 <= #" & q2 & "#"
tbl.Filter = Filter
End If
If txt = "本年" Then
Filter = "录入日期 >= #" & y1 & "# And 录入日期 <= #" & y2 & "#"
tbl.Filter = Filter
End If
If txt = "上年" Then
Filter = "录入日期 >= #" & sy1 & "# And 录入日期 <= #" & sy2 & "#"
tbl.Filter = Filter
End If
If txt = "所有" Then
Filter = ""
tbl.Filter = Filter
End If