Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a program that uses countdown timers, it works but I am trying to do something new with this blender timer. It uses a NumericUpDown and is supposed to add 5 minutes for each value, 1 being 5 minutes and 2 being 10 minutes etc. I did find a way of adding 5 minutes to BlenderCountDownFrom but when pressing the BlenderButton to stop it kept the new value. I am a complete novice and don't know what I am doing so the code is probably horrible! The actual countdown code I got from an example on the internet.

VB
Dim BlenderCountDownFrom As New TimeSpan(0, 5, 1)

Dim BlenderStopwatch As New Stopwatch

 Private Sub BlenderButton_Click(sender As Object, e As EventArgs) Handles BlenderButton.Click
        If BlenderButton.Text = "Start" Then
            BlenderTimer.Interval = 100
            BlenderButton.Text = "Stop"
            BlenderTimer.Start()
            BlenderStopwatch.Reset()
            BlenderStopwatch.Start()
        Else
            BlenderButton.Text = "Start"
            My.Computer.Audio.Stop()
            BlenderTimerLabel.BackColor = Color.White
            BlenderTimer.Stop()
            BlenderStopwatch.Stop()

            BlenderTimerLabel.Text = ("00:05:00")
            Me.MiscTab.Text = "Misc"
        End If
    End Sub

    Private Sub BlenderTimer_Tick(sender As Object, e As EventArgs) Handles BlenderTimer.Tick
        If BlenderStopwatch.Elapsed <= BlenderCountDownFrom Then
            Dim toGo As TimeSpan = BlenderCountDownFrom - BlenderStopwatch.Elapsed
            BlenderTimerLabel.Text = String.Format("{0:00}:{1:00}:{2:00}", toGo.Hours, toGo.Minutes, toGo.Seconds)
        Else
            BlenderTimer.Stop()
            My.Computer.Audio.Play(My.Resources.Alarm.Blender, AudioPlayMode.BackgroundLoop)
            Me.MiscTab.Text = "Alarm"
            BlenderStopwatch.Stop()
            BlenderTimerLabel.BackColor = Color.Red
        End If
    End Sub

    Private Sub BlenderSetButton_Click(sender As Object, e As EventArgs) Handles BlenderSetButton.Click
        Blender.HowManyBlender()
    End Sub



Public Class Blender


    Public Shared Function HowManyBlender()

        'Must be a better way than this!

        If JBCountdown.BlenderUpDown.Value = 1 Then
            JBCountdown.BlenderTimerLabel.Text = ("00:05:00")
        End If

        If JBCountdown.BlenderUpDown.Value = 2 Then
            JBCountdown.BlenderTimerLabel.Text = ("00:10:00")
        End If

        If JBCountdown.BlenderUpDown.Value = 3 Then
            JBCountdown.BlenderTimerLabel.Text = ("00:15:00")
        End If

        If JBCountdown.BlenderUpDown.Value = 4 Then
            JBCountdown.BlenderTimerLabel.Text = ("00:20:00")
        End If

        If JBCountdown.BlenderUpDown.Value = 5 Then
            JBCountdown.BlenderTimerLabel.Text = ("00:25:00")
        End If

        Return (0)
    End Function

End Class


What I have tried:

I added 5 minutes to BlenderCountDownFrom, can't remember exactly how but it kept the value when I pressed the stop button (same as start button just label changes) I need to go back to 5 minutes unless a new value is set by the NumericUpDown
Posted
Updated 18-Aug-19 19:56pm
v3
Comments
[no name] 16-Aug-19 19:05pm    
Just add / subtract some multiple of the TIMER INTERVAL. The rest is crazy-making.
funkymunkey99 18-Aug-19 11:28am    
I'm not sure how I could do that? The program uses a stopwatch and timespan when stopwatch is greater than timespan it does the alarm, not sure where timer interval comes into it?

1 solution

Not sure i understand you well, but to change timer interval change Interval property:

VB.NET
BlenderTimer.Interval = 100 'new value here


See:
Timer.Interval Property (System.Timers) | Microsoft Docs[^]
Timer.Interval Property (System.Windows.Forms) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900