Results 1 to 5 of 5

Thread: current timer value

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    8

    Question 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

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: current timer value

    Quote 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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    8

    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

  4. #4
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width