Solved

NumericUpDown increment Time value

Posted on 2007-04-03
6
800 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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