我必须从DateTimePicker
向星期五添加7天。这是我的代码。
我知道它会创建一个循环,因为星期五是星期五的7天。然后它会重复,我怎么能阻止它在第一个星期五之后重复?
If Me.DateTimePicker1.Value.DayOfWeek = DayOfWeek.Saturday _
Or Me.DateTimePicker1.Value.DayOfWeek = DayOfWeek.Sunday Then
If Me.DateTimePicker1.Value.DayOfWeek = DayOfWeek.Saturday Then
Me.DateTimePicker1.Value = Me.DateTimePicker1.Value.AddDays(-1)
Else
Me.DateTimePicker1.Value = Me.DateTimePicker1.Value.AddDays(-2)
End If
End If
If Me.DateTimePicker1.Value.DayOfWeek = DayOfWeek.Friday Then
Me.DateTimePicker1.Value = Me.DateTimePicker1.Value.AddDays(7)
End If
End Sub
End Class
答案 0 :(得分:1)
创建一个全局状态变量:
Dim busy as Boolean
busy = False
在您的潜艇中,您可以执行以下操作:
Sub dateTimePicker1Change...
if not busy then
busy = True
' Your logic here
busy = False
End if
End Sub
因此,您的事件应该触发两次,但是当您仍在处理第一个事件时第二次触发时,您已将busy
状态设置为True
,这会立即导致返回第二个事件处理(没有进一步触发)。