Solved

NumericUpDown increment Time value

Posted on 2007-04-03
6
799 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

17 Experts available now in Live!

Get 1:1 Help Now