kasowitz
asked on
NumericUpDown increment Time value
Hi,
I am trying to get a NumericUpDown increment to behave like a time value. I want to increment the time in 5min intervals (.05), but when the value reaches 0.55 I want the next value to be 1.00 to represent 1 hour. What would be the easiest way to do this ? Any ideas ?
Thanks for all your help.
I am trying to get a NumericUpDown increment to behave like a time value. I want to increment the time in 5min intervals (.05), but when the value reaches 0.55 I want the next value to be 1.00 to represent 1 hour. What would be the easiest way to do this ? Any ideas ?
Thanks for all your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could change your code to include a variable to store the last value, and then check if the new value is higher or lower than the old one, then perform the relevant action:
Private _lastValue As Decimal = 0
Private Sub NumericUpDown1_ValueChange d(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChange d
Dim newValue As Decimal = Me.NumericUpDown1.Value
If Me.NumericUpDown1.Value Mod 1 > 0.59 Then
If newValue > _lastValue Then
newValue += 1
newValue -= newValue Mod 1
Else
newValue -= 1
newValue -= newValue Mod 1
newValue += 0.59
End If
Me.NumericUpDown1.Value = newValue
End If
_lastValue = newValue
End Sub
Private _lastValue As Decimal = 0
Private Sub NumericUpDown1_ValueChange
Dim newValue As Decimal = Me.NumericUpDown1.Value
If Me.NumericUpDown1.Value Mod 1 > 0.59 Then
If newValue > _lastValue Then
newValue += 1
newValue -= newValue Mod 1
Else
newValue -= 1
newValue -= newValue Mod 1
newValue += 0.59
End If
Me.NumericUpDown1.Value = newValue
End If
_lastValue = newValue
End Sub
ASKER
Awesome, Thanks :)
Another thing if you dont mind ?....When the value goes up to "2.00" and I want to go back down to "1.55" it goes to "0.55" instead. Why is that?
This is turning into a lot more code then I ever thought would be needed of this ! :)
Another thing if you dont mind ?....When the value goes up to "2.00" and I want to go back down to "1.55" it goes to "0.55" instead. Why is that?
This is turning into a lot more code then I ever thought would be needed of this ! :)
Sorry - I left in a line that should not have been there! Take out:
newValue -= 1
newValue -= 1
ASKER
Perfect ! Thanks :)
ASKER
Your code works perfect, but once you reach "1.00" you cannot go back down to "0.55" , what would I need to stick in there to be able to go backwards as well ?
Thanks a ton for your help !!