Solved

NumericUpDown increment Time value

Posted on 2007-04-03
6
797 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:kasowitz
  • 3
  • 3
6 Comments
 
LVL 7

Accepted Solution

by:
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

by:kasowitz
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

by:dctuck
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:kasowitz
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

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

Author Comment

by:kasowitz
ID: 18845211
Perfect ! Thanks :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now