Timer Control in vb.net

Example and properties of Timer Control

Page 1 of 1

8 Replies - 22614 Views - Last Post: 26 September 2009 - 04:11 AM Rate Topic: -----

#1 SnnehalGhodke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 09

Timer Control in vb.net

Posted 25 September 2009 - 08:32 PM

How to use Timer control in vb.net? and what are different properties of Timer Control?
Is This A Good Question/Topic? 0
  • +

Replies To: Timer Control in vb.net

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Timer Control in vb.net

Posted 25 September 2009 - 09:12 PM

Timers typically have Start/Stop and an Interval in their event handler - interval is in milliseconds - real resolution can be in th 55 ms range. Try the documentation in VB.Net - it is pretty good and includes samples.
Was This Post Helpful? 0
  • +
  • -

#3 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 277
  • Joined: 29-August 08

Re: Timer Control in vb.net

Posted 25 September 2009 - 09:16 PM

Load a timer on form just as you would anything else. Then with the timer selected look at some of the properties. If you want the timer start when the application is first launched change enabled to true, otherwise when you want to start the you can use
Timer1.Start()
or
Timer1.Enabled=True
This should get you started.
Was This Post Helpful? 0
  • +
  • -

#4 SnnehalGhodke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 09

Re: Timer Control in vb.net

Posted 25 September 2009 - 09:19 PM

View Postmark.bottomley, on 25 Sep, 2009 - 08:12 PM, said:

Timers typically have Start/Stop and an Interval in their event handler - interval is in milliseconds - real resolution can be in th 55 ms range. Try the documentation in VB.Net - it is pretty good and includes samples.


Thank u, can u tell me any example of tht?

View Postcamckee316, on 25 Sep, 2009 - 08:16 PM, said:

Load a timer on form just as you would anything else. Then with the timer selected look at some of the properties. If you want the timer start when the application is first launched change enabled to true, otherwise when you want to start the you can use
Timer1.Start()
or
Timer1.Enabled=True
This should get you started.

Thank u, Can u tell me any example of tht? so that i can get the details of that control.
Was This Post Helpful? 0
  • +
  • -

#5 PDUNZ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 372
  • Joined: 17-July 09

Re: Timer Control in vb.net

Posted 25 September 2009 - 09:26 PM

Timer Control
Was This Post Helpful? 0
  • +
  • -

#6 SnnehalGhodke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 09

Re: Timer Control in vb.net

Posted 25 September 2009 - 09:28 PM

View PostSnnehalGhodke, on 25 Sep, 2009 - 08:19 PM, said:

View Postmark.bottomley, on 25 Sep, 2009 - 08:12 PM, said:

Timers typically have Start/Stop and an Interval in their event handler - interval is in milliseconds - real resolution can be in th 55 ms range. Try the documentation in VB.Net - it is pretty good and includes samples.


Thank u, can u tell me any example of tht?

View Postcamckee316, on 25 Sep, 2009 - 08:16 PM, said:

Load a timer on form just as you would anything else. Then with the timer selected look at some of the properties. If you want the timer start when the application is first launched change enabled to true, otherwise when you want to start the you can use
Timer1.Start()
or
Timer1.Enabled=True
This should get you started.

Thank u, Can u tell me any example of tht? so that i can get the details of that control.

hi
i have two textboxs , i want to show 1 to 10 in thoses textboxes but using timer control with different intervals.
so how to do that?
Was This Post Helpful? 0
  • +
  • -

#7 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Timer Control in vb.net

Posted 25 September 2009 - 09:30 PM

In the timer event handlers, just read the text box, check for < 10 and add one if it is still less than ten else timer.disable. (I'm giving as much code as you have shown)
Was This Post Helpful? 0
  • +
  • -

#8 SnnehalGhodke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 09

Re: Timer Control in vb.net

Posted 25 September 2009 - 09:50 PM

View PostPDUNZ, on 25 Sep, 2009 - 08:26 PM, said:


i want to show 1 to 10 in 2 different textboxes using 2 different timer.
is this code works?
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
Timer2.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim i As Integer
For i = 0 To 10
Timer1.Enabled = True
TextBox1.Text = i
Timer1.Interval = 10000
Timer1.Enabled = False
Next

End Sub


Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim i As Integer
For i = 0 To 10
Timer2.Enabled = True
TextBox2.Text = i
Timer2.Interval = 5000
Timer2.Enabled = False
Next
End Sub

View Postmark.bottomley, on 25 Sep, 2009 - 08:30 PM, said:

In the timer event handlers, just read the text box, check for < 10 and add one if it is still less than ten else timer.disable. (I'm giving as much code as you have shown)

want to show 1 to 10 in 2 different textboxes using 2 different timer.
is this code works?
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
Timer2.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim i As Integer
For i = 0 To 10
Timer1.Enabled = True
TextBox1.Text = i
Timer1.Interval = 10000
Timer1.Enabled = False
Next

End Sub


Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim i As Integer
For i = 0 To 10
Timer2.Enabled = True
TextBox2.Text = i
Timer2.Interval = 5000
Timer2.Enabled = False
Next
End Sub
Was This Post Helpful? 0
  • +
  • -

#9 PDUNZ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 372
  • Joined: 17-July 09

Re: Timer Control in vb.net

Posted 26 September 2009 - 04:11 AM

Your getting there, but that wouldnt work. What your code will do is because you have an FOR loop, it would only take 1 tick to count to 10.

You can do it many ways, try it this way - note the differences. I havnt used any variables (bad practice but should get you started), just reading the number straight from the textbox and adding 1 on each tick. If the value = 10, the timer(s) stop. Also, you can also add in an ELSE in the If statments and put the textbox.text += 1 in there.

Form Load
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		' Set Timer Intervals.
		Timer1.Interval = 10000
		Timer2.Interval = 5000

		' Set initial value in textboxes.
		TextBox1.Text = "0"
		TextBox2.Text = "0"

		' Start Timers.
		Timer1.Start()
		Timer2.Start()
	End Sub



Timer1 Tick, change relavent parts for timer2.tick.
	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

		TextBox1.Text += 1 ' Add 1 to the value in Textbox.

		If TextBox1.Text = 10 Then ' If the value = 10 then timer1 stop.
			Timer1.Stop()
		End If

	End Sub



Also, you can also add in an ELSE in the If statments and put the textbox.text += 1 in there so the above timer.tick code now looks like this.
	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

		If TextBox1.Text = 10 Then ' If the value = 10 then timer1 stop.
			Timer1.Stop()
		Else
			TextBox1.Text += 1 ' Add 1 to the value in Textbox.
		End If

	End Sub



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

		If TextBox1.Text < 10 Then
			TextBox1.Text += 1 ' Add 1 to the value in Textbox.
		Else
			Timer1.Stop()
		End If

	End Sub



Hope that helps.

This post has been edited by PDUNZ: 26 September 2009 - 04:18 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1