Solved

# NumericUpDown increment Time value

Posted on 2007-04-03
806 Views
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 ?

0
Question by:kasowitz
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 3

LVL 7

Accepted Solution

dctuck earned 500 total points
ID: 18844187
This probably isn't the cleanest way of doing it, but you could put something similar to this in the ValueChanged event of your NumericUpDown:

If Me.NumericUpDown1.Value Mod 1 > 0.55 Then
Dim newValue As Decimal = Me.NumericUpDown1.Value
newValue += 1
newValue -= newValue Mod 1
Me.NumericUpDown1.Value = newValue
End If
0

Author Comment

ID: 18844317
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 !!
0

LVL 7

Expert Comment

ID: 18844415
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
0

Author Comment

ID: 18844512
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 ! :)
0

LVL 7

Expert Comment

ID: 18844981
Sorry - I left in a line that should not have been there! Take out:
newValue -= 1
0

Author Comment

ID: 18845211
Perfect ! Thanks :)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

XML Literals are a great way to handle XML files and the community doesnâ€™t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with wâ€¦
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can â€¦
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In thisâ€¦
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (httpsâ€¦
###### Suggested Courses
Course of the Month2 days, 5 hours left to enroll