Link to home
Start Free TrialLog in
Avatar of kasowitz
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.
ASKER CERTIFIED SOLUTION
Avatar of dctuck
dctuck
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kasowitz
kasowitz

ASKER

Thanks,  I wasnt sure if there was another way around it or if I was going to have to use code like you just provided me with.

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 !!
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_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        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
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 ! :)
Sorry - I left in a line that should not have been there! Take out:
newValue -= 1
Perfect ! Thanks :)