2 Replies - 20019 Views - Last Post: 23 March 2010 - 04:34 AM Rate Topic: -----

#1 xairzx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-March 10

Simple Timer with Progress Bar and NumericUpDown

Posted 21 March 2010 - 11:38 PM

hi all
im creating a simple timer.it have NumericUpDown and Progress Bar.
i use NumericUpDown to set the timer in minutes.I also put Progress Bar to indicates the percentage of times completed.For example if i set the timer to 1 minutes so if it at 0.5 minutes the Progress Bar will show 50% completed.But the problem here is the Progress Bar is not working.

here is the coding

Public Class Form1
    Inherits System.Windows.Forms.Form

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick


        If ProgressBar1.Value < ProgressBar1.Maximum Then
            ProgressBar1.Value += 2
        Else
            ProgressBar1.Value = ProgressBar1.Minimum
        End If

        lblmsg.Text = "Percentage Complete : " & ProgressBar1.Value & "%"
        Timer1.Enabled = False

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Minutes As Integer = NumericUpDown1.Value
        Timer1.Interval = Minutes * 60 * 1000
        Timer1.Enabled = True
        MsgBox("The timer has been set.", MsgBoxStyle.Information And MsgBoxStyle.OKOnly, "Timer Set")

    End Sub

    Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged

    End Sub

    Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click

    End Sub
End Class



any thought?

Is This A Good Question/Topic? 0
  • +

Replies To: Simple Timer with Progress Bar and NumericUpDown

#2 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Simple Timer with Progress Bar and NumericUpDown

Posted 22 March 2010 - 07:04 AM

Hi,

Try this:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        ProgressBar1.Value += 1
        Label1.Text = ProgressBar1.Value & "%"
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Enabled = False
        End If


    End Sub
   
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Minutes As Integer = NumericUpDown1.Value
        Timer1.Interval = Minutes * 100

        MsgBox("The timer has been set.", MsgBoxStyle.Information And MsgBoxStyle.OkOnly, "Timer Set")
        Timer1.Enabled = True

    End Sub


If you calculated the time like this:

Minutes * 60 *1000 = 5 minutes * 60 = 300 minutes * 1000= 300000 seconds.

That's way you didn't shaw the timers working.
Was This Post Helpful? 0
  • +
  • -

#3 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

Re: Simple Timer with Progress Bar and NumericUpDown

Posted 23 March 2010 - 04:34 AM

I have a solution to this problem as well, it's not as simple as Luc001's but you should be able to see how I have calculated percentages and time.

Not very elegant I admit, but I did write it in 5 minutes..

Public Class Form1
    Dim Ticker As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim time As Integer = NumericUpDown1.Value * 60
        ProgressBar1.Maximum = time
        ProgressBar1.Value = 0
        Ticker = 0
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Ticker = ProgressBar1.Maximum Then
            Timer1.Enabled = False
        Else
            Ticker = Ticker + 1
        End If
        ProgressBar1.Value = Ticker
        Dim Percent As Integer = ((ProgressBar1.Value / ProgressBar1.Maximum) * 100)

        Label1.Text = Percent & "% Completed"
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = Timer1.Enabled <> True
        Ticker = 0
    End Sub
End Class


This post has been edited by Saldash: 23 March 2010 - 04:34 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1