|
-
May 21st, 2007, 06:09 AM
#1
Thread Starter
New Member
current timer value
Hello,
I want to know if it's possible to see the current value of the timer enable. I want to click on a button and that shows me the time value of the timer.
Thanks
-
May 21st, 2007, 06:27 AM
#2
Re: current timer value
 Originally Posted by jonnycage
Hello,
I want to know if it's possible to see the current value of the timer enable. I want to click on a button and that shows me the time value of the timer.
Thanks
Hi,
You can try this;
Code:
TextBox1.Text = Timer1.Interval
Wkr,
sparrow1
-
May 21st, 2007, 06:41 AM
#3
Thread Starter
New Member
Re: current timer value
Hi,
sparrow1 that just return to me the value of the interval that i've set.
For example:
timer.interval=3000
That code that you gave me returns 3000 and i want the current value of the timer , for example: current_timer:1565
-
May 21st, 2007, 06:46 AM
#4
Re: current timer value
If you want the number of elapsed ticks, use the tick event;
Code:
Dim Inc As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Timer1.Tick
Inc += 1
End Sub
When the button is clicked, display the value of Inc. The duration will have been Inc*Interval seconds.
If you want real time as in time of day when the timer was accessed then do;
Code:
Option Strict On
Public Class Form1
Dim CurrentTime As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim t As New System.Timers.Timer
t.Interval = 1000
t.Enabled = True
t.SynchronizingObject = Me
AddHandler t.Elapsed, AddressOf TimerState
Dim ShowTime As New Button
ShowTime.Text = "Show Time"
AddHandler ShowTime.Click, AddressOf ShowTimeClick
Me.Controls.Add(ShowTime)
End Sub
Public Sub TimerState(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
CurrentTime = e.SignalTime.ToString
End Sub
Private Sub ShowTimeClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(CurrentTime)
End Sub
End Class
Last edited by Bulldog; May 21st, 2007 at 07:08 AM.
-
May 21st, 2007, 06:47 AM
#5
Re: current timer value
There is no such value associated with a Timer. If you want to calculate the time remaining until the next Tick event then it's up to you to have saved the current time on the last Tick and calculate it yourself. The easiest way would be to use a Stopwatch object and reset it each Tick. Note though that there Tick event handlers will not necessarily be executed exactly on the Interval.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|