Solved

NumericUpDown increment Time value

Posted on 2007-04-03
6
805 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
[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
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with exporting to excel 4 45
VB.Net - MemoryMappedFiles - Confirm receipt 2 36
ASP.NET Calendar Control 5 26
VB.Net Data Class 1 21
Article by: jpaulino
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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