S
Sheldon
Hello -
I found the following code on the Internet which is perfect for my needs
with datetimepicker controls:
Private Sub dtpOther_ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dtpOther.ValueChanged
Dim newTime As DateTime = dtpOther.Value
Dim hr As Integer = newTime.Hour
Dim min As Integer = newTime.Minute
Dim sec As Integer = newTime.Second
If (oldTime.Hour = 23 AndAlso newTime.Hour = 0) OrElse (oldTime.Hour
= 0 AndAlso newTime.Hour = 23) Then
hr = oldTime.Hour
End If
If (oldTime.Minute = 59 AndAlso newTime.Minute = 0) OrElse
(oldTime.Minute = 0 AndAlso newTime.Minute = 59) Then
min = oldTime.Minute
End If
If (oldTime.Second = 59 AndAlso newTime.Second = 0) OrElse
(oldTime.Second = 0 AndAlso newTime.Second = 59) Then
sec = oldTime.Second
End If
If hr <> newTime.Hour OrElse min <> newTime.Minute OrElse sec <>
newTime.Second Then
dtpOther.Value = DateTime.Now.Date.Add(New TimeSpan(hr, min, sec))
End If
oldTime = dtpOther.Value
End Sub
I have nine timepicker controls which all need to do the same thing as the
above. How can I consolidate it in code instead of doing one each of the Sub
for each of the controls?
I know it's an elementary question for a lot of you, but I'm just learning
this stuff.
Any help will be appreciated!
I found the following code on the Internet which is perfect for my needs
with datetimepicker controls:
Private Sub dtpOther_ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dtpOther.ValueChanged
Dim newTime As DateTime = dtpOther.Value
Dim hr As Integer = newTime.Hour
Dim min As Integer = newTime.Minute
Dim sec As Integer = newTime.Second
If (oldTime.Hour = 23 AndAlso newTime.Hour = 0) OrElse (oldTime.Hour
= 0 AndAlso newTime.Hour = 23) Then
hr = oldTime.Hour
End If
If (oldTime.Minute = 59 AndAlso newTime.Minute = 0) OrElse
(oldTime.Minute = 0 AndAlso newTime.Minute = 59) Then
min = oldTime.Minute
End If
If (oldTime.Second = 59 AndAlso newTime.Second = 0) OrElse
(oldTime.Second = 0 AndAlso newTime.Second = 59) Then
sec = oldTime.Second
End If
If hr <> newTime.Hour OrElse min <> newTime.Minute OrElse sec <>
newTime.Second Then
dtpOther.Value = DateTime.Now.Date.Add(New TimeSpan(hr, min, sec))
End If
oldTime = dtpOther.Value
End Sub
I have nine timepicker controls which all need to do the same thing as the
above. How can I consolidate it in code instead of doing one each of the Sub
for each of the controls?
I know it's an elementary question for a lot of you, but I'm just learning
this stuff.
Any help will be appreciated!