Page 1 of 2 12 LastLast
Results 1 to 40 of 41

Thread: need help on my timer program[ResolveD]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123

    Resolved need help on my timer program[ResolveD]

    Hi, I would like the coding for timer that is in 00:00:00.
    Last edited by private1337; Nov 21st, 2004 at 03:09 AM.
    The Power Of Sharing Knowledge!

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: need help on my timer program

    Originally posted by private1337
    Hi, I would like the coding for timer that is in 00:00:00.
    You will have to be more explicit.

    Do you mean "Timer" or "Time"?

    If the latter, then presumably you want the time displayed down to the second.

    VB Code:
    1. TextBox1.Text = CStr(Format(Now, "hh:mm:ss"))

    If you want the 24 hour clock then use HH instead of hh
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    I mean count up and count down timer like watch. If got alarm coding for people to set specifc time, I will be more happy about it
    The Power Of Sharing Knowledge!

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    To set a time as an alarm point you use a timer tick event to check Now.

    If the user is entering a time period, one way is when you want to start the period, to set a variable to Now.AddHours (or minutes or seconds as you wish); set the timer interval to the appropriate level and check for Now>= the variable.

    If the user is entering the actual alarm time then you simply use that entry for the variable value.

    Coding a stopwatch is more complicated and someone else may come up with an answer before I have worked it out.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Thanks anyway..
    The Power Of Sharing Knowledge!

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Experiment with the following;

    VB Code:
    1. Private Sub StartCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    2.          ZeroTime = Format(CDate("00:00:00"), "HH:mm:ss")
    3.         Timer1.Enabled = True
    4.         Timer1.Interval = 1000
    5.     End Sub
    6.  
    7.  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    8.          ZeroTime = ZeroTime.AddSeconds(1)
    9.         TextBox3.Text = (CStr(Format(ZeroTime, "hh:mm:ss")))
    10.         TextBox3.Update()
    11.     End Sub

    That has a bug at the moment. The counting starts at 12.00.00 instead of 00.00.00.
    Last edited by taxes; Nov 3rd, 2004 at 08:52 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    HI,

    Cured it!!

    VB Code:
    1. Dim ZeroTime As Date    '  Form scope
    2. Dim RunTime As Date
    3. Dim EndTime As Date  ' depends on whether you are going
    4.                                        to use a time or a period
    5. Dim bTimer As Boolean = False
    6.  
    7.   Private Sub ButtonStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    8.  
    9.         ZeroTime = Format(CDate("00:00:00"), "HH:mm:ss")
    10.         RunTime=ZeroTime
    11.         Timer1.Enabled = True
    12.         Timer1.Interval = 1000
    13.  
    14.  
    15.     End Sub
    16.  
    17.  
    18.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    19.  
    20.   If bTimer = False Then
    21.         RunTime = RunTime.AddSeconds(1)
    22.         TextBox3.Text = (CStr(Format(RunTime, "HH:mm:ss")))
    23.         Here put code to check if EndTime has been reached or
    24.         passed.
    25.   End If
    26.  
    27.     End Sub
    28.  
    29.  Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
    30.         If btnPause.Text = "Pause" Then
    31.             btnPause.Text = "Resume"
    32.             bTimer = True
    33.         Else
    34.             btnPause.Text = "Pause"
    35.             bTimer = False
    36.         End If
    37.     End Sub

    If you want to count down then amend the appropriate line to

    RunTime = RunTime.AddSeconds(-1)
    Last edited by taxes; Nov 5th, 2004 at 09:52 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    oh... very cool!!! Thanks
    The Power Of Sharing Knowledge!

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Hi, can I have a pause/resume button? And can I check it to the format 00:00:00:00 so that I have more accurate timing.
    The Power Of Sharing Knowledge!

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Use an If ... Then around the timer_tick event code, checking the state of a boolean varied by the button. Change the text of the button in accordance with the action next required.

    With regard to hundredths of a second, I will have to experiment. Have a go yourself and post the result.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Oh.. Can u give me the If Then coding too cause I not really understand.. Thanks Wish to hear from u soon the hudnreth of second...
    The Power Of Sharing Knowledge!

  12. #12
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I've amended my posted code to include the pause/restart facility.
    I was hoping someone else had the answer to the 100's second. I will work on it.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  13. #13
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Timers are not accurate, setting an interval of 1000 will not accurately reflect 1 second.

    If I were you I'd set it to something like 50 and then use an IF to decide whether a second has passed since the last time the clock was updated, if so then add 1 second to the clock. From second This will be much more accurate.
    I don't live here any more.

  14. #14
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Setting the interval to 5 should fix the 1/100th problem too.
    I don't live here any more.

  15. #15
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I cannot find any format which will display less than 1 second, so you will have to create your own custom format. That is beyond me at the moment so I would have to approach the matter differently.

    Instead of using the DateTime approach, simply increment a double variable by 1 on every timer_tick event (set the interval to 10 for onehundredth) and then evaluate the variable and display it in the textbox ( first divide by 10 then by 60, then by 60 to give you the hours, minutes, seconds and 100'ths)

    Have a go at coding that and post your attempt, cos me simply telling you is not helping you.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  16. #16
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by wossname
    Setting the interval to 5 should fix the 1/100th problem too.
    Hi, is there a standard format to display 10'ths of a second?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  17. #17
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Timespan.Ticks, take a look.
    I don't live here any more.

  18. #18
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by wossname
    Timespan.Ticks, take a look.
    Sorry, my brain seems to have gone numb. The MSDN article does not say how to use it in formatting. Also, am I reading it right when it says a Tick is one ten-millionth of a second???????

    I did look at timespan before and rejected it for minute period counting purposes but if you know different please advise.

    I have incorporated your recommendation to use shorter intervals for the timer for greater accuracy -- thanks.

    Private 1337.

    So far I have the following code. It does the calculations OK but I am having problem with the display. It does not recognise the minutes break at 60 seconds etc. See what you can do with it.

    VB Code:
    1. Dim ZeroTime, EndTime, RunTime, TimeLeft As Double
    2.    Dim sTime As String
    3.    Dim bTimer As Boolean = False  
    4.  
    5.  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    6.  
    7.         ZeroTime = 0
    8.         EndTime = 0
    9.         Timer1.Enabled = True
    10.         Timer1.Interval = 1
    11.         sTime = ""
    12.  End Sub
    13.  
    14.  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    15.         If bTimer = False Then
    16.             EndTime += 0.1
    17.             TimeLeft = EndTime + 0.001
    18.             If TimeLeft >= 1 Then
    19.                 sTime = CStr(Int(TimeLeft))  ' display 100'ths second
    20.                 RunTime = TimeLeft Mod 100
    21.                 TimeLeft = Int(TimeLeft / 100)
    22.                 sTime = CStr(RunTime) & ":" & sTime
    23.                 RunTime = TimeLeft Mod 60
    24.                 TimeLeft = Int(TimeLeft / 60)
    25.                 sTime = CStr(RunTime) & ":" & sTime
    26.                 RunTime = TimeLeft Mod 60
    27.                 TimeLeft = Int(TimeLeft / 60)
    28.                 sTime = CStr(RunTime) & ":" & sTime
    29.                 TextBox3.Text = sTime & CStr(Int(TimeLeft))
    30.             End If
    31.  
    32.         End If
    33. End Sub
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  19. #19
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Any progress?


    I have solved nearly all of the problem, but the following code still has two bugs.

    The seconds field does not contain a leading zero when there is only one digit.

    The Hundredths field does not show up, even though the underlying calculation is taking place.

    VB Code:
    1. Dim ZeroTime, EndTime, RunTime, TimeLeft As Double
    2.     Dim sTime As String
    3.     Dim bTimer As Boolean = False
    4.  
    5.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    6.  
    7.         ZeroTime = 0
    8.         EndTime = 23700000
    9.         Timer1.Enabled = True
    10.         Timer1.Interval = 1
    11.         sTime = ""
    12.     End Sub
    13.  
    14.  
    15.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    16.  
    17.         If bTimer = False Then
    18.             sTime = ""
    19.             EndTime += 1                 'every 1000 th sec   increase by 1.
    20.             TimeLeft = EndTime + 0.001       'ensure value is rounded up
    21.             Runtime = Int(TimeLeft) / 100 / 60 / 60     'calculate hours
    22.             sTime = FormatRunTime(CStr(Int(Runtime)))
    23.             TimeLeft = (Runtime - Int(Runtime)) * 60 + 0.0001  'calculate minutes
    24.             sTime = FormatRunTime(CStr(Int(TimeLeft)))
    25.             TimeLeft = (TimeLeft - Int(TimeLeft)) * 60    'calculates seconds
    26.             sTime = FormatRunTime(CStr(Int(TimeLeft)))
    27.             TimeLeft = Int(TimeLeft - Int(TimeLeft)) * 100 + 0.0001   'calculates 100 ths
    28.             sTime = FormatRunTime(CStr(Int(TimeLeft)))
    29.  
    30.  
    31.             TextBox3.Text = sTime
    32.         End If
    33.     End Sub
    34.  
    35.     Private Function FormatRunTime(ByVal rt As String)
    36.         If Val(rt) < 1 Then
    37.             rt = "00"
    38.         ElseIf Val(rt) < 10 Then
    39.             rt = "0" & rt
    40.         End If
    41.         rt = sTime & Format(Val(rt), 0) & ":"
    42.         Return rt
    43.     End Function
    44.  
    45.   Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
    46.         If btnPause.Text = "Pause" Then
    47.             btnPause.Text = "Resume"
    48.             bTimer = True
    49.         Else
    50.             btnPause.Text = "Pause"
    51.             bTimer = False
    52.         End If
    53.     End Sub
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  20. #20
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Cracked it! This code can be tidied up a little by using a function to calculate the time values.

    VB Code:
    1. Dim ZeroTime, EndTime, RunTime, TimeLeft As Double
    2.     Dim sTime As String
    3.     Dim bTimer As Boolean = False
    4.  
    5.  
    6.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    7.  
    8.         ZeroTime = 0
    9.         EndTime = 23712345
    10.         Timer1.Enabled = True
    11.         Timer1.Interval = 1
    12.         sTime = ""
    13.  
    14.  
    15.     End Sub
    16.  
    17.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    18.  
    19.         If bTimer = False Then
    20.             sTime = ""
    21.             EndTime += 1                 'every 1000 th sec   increase by 1.
    22.             TimeLeft = EndTime + 0.001       'ensure value is rounded up
    23.             Runtime = Int(TimeLeft) / 100 / 60 / 60     'calculate hours
    24.             sTime = FormatRunTime(CStr(Int(Runtime)))
    25.             TimeLeft = (Runtime - Int(Runtime)) * 60 + 0.0001  'calculate minutes
    26.             sTime = FormatRunTime(CStr(Int(TimeLeft)))
    27.             TimeLeft = (TimeLeft - Int(TimeLeft)) * 60 + 0.0001  'calculates seconds
    28.             sTime = FormatRunTime(CStr(Int(TimeLeft)))
    29.             TimeLeft = (TimeLeft - Int(TimeLeft)) * 100 + 0.0001   'calculates 100 ths
    30.             sTime = FormatRunTime(CStr(Int(TimeLeft)))
    31.  
    32.  
    33.             TextBox3.Text = sTime
    34.  
    35.         End If
    36.  End Sub
    37.  
    38.     Private Function FormatRunTime(ByVal rt As String)
    39.         rt = Format(Val(rt), 0)
    40.         If Val(rt) < 1 Then
    41.             rt = "00"
    42.         ElseIf Val(rt) < 10 Then
    43.             rt = "0" & rt
    44.         End If
    45.         rt = sTime & rt & ":"
    46.         Return rt
    47.     End Function
    48.  
    49.  
    50.  
    51.     Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
    52.         If btnPause.Text = "Pause" Then
    53.             btnPause.Text = "Resume"
    54.             bTimer = True
    55.         Else
    56.             btnPause.Text = "Pause"
    57.             bTimer = False
    58.         End If
    59.     End Sub

    Now someone will come up with a way to format time in 100 ths sec
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Thanks for everyone help especially taxes. Now the coding is getting more profound... But now the timer starts @ 65:52:03:00: and it seems to have the hundreth of second but start at the wrong time? Any idea??

    Btw, can u modify the Pause coding

    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
    If btnPause.Text = "Pause" Then
    btnPause.Text = "Resume"
    bTimer = True
    Else
    btnPause.Text = "Pause"
    bTimer = False
    End If
    End Sub

    to if I never click the Start button, the Pause button can't be clicked?
    The Power Of Sharing Knowledge!

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Originally posted by taxes
    If you want to count down then amend the appropriate line to
    RunTime = RunTime.AddSeconds(-1)
    I can't set to count down mode when I modify to -1. It prompt me

    An unhandled exception has occured in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will be shut down immediately.

    Ticks must be between DatEime.MinValue.Ticks and
    Date.Time.MaxValue.Ticks.
    Parameter name: ticks

    when I Start the timer using the Start button. Any idea?
    The Power Of Sharing Knowledge!

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Originally posted by wossname
    Setting the interval to 5 should fix the 1/100th problem too.
    Ya.. that is what I want. But if it have more 1 more 00: in front that will be better. So it will be 00:00:00:00 . Is it need to change the interval again to which number?
    The Power Of Sharing Knowledge!

  24. #24
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by private1337
    Ya.. that is what I want. But if it have more 1 more 00: in front that will be better. So it will be 00:00:00:00 . Is it need to change the interval again to which number?
    I don't understand you. The code I posted DOES display

    00:00:00:00

    i.e. hours, minutes, seconds, hundredths. If you are getting a diferent result, check the code you are using.

    The Timer.Interval simply sets the time between firing of the Timer_Click events. Settin the Interval to 1000 fires the event every one-thousandth of a second, to give you better accuracy as Wossname posted.

    By the way, there is no point in using another function to calculate the time valuse as I mentioned, because you actually have to write more code that way.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  25. #25
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by private1337
    Thanks for everyone help especially taxes. Now the coding is getting more profound... But now the timer starts @ 65:52:03:00: and it seems to have the hundreth of second but start at the wrong time? Any idea??

    Sorry, I set the start time to a figure which enabled me to test the hours coding and forgot to reset it when I posted

    Change EndTime = 23712345

    to EndTime=ZeroTime



    To do what you wanted to the btnPause:

    In the Load event of your form put

    btnPause.Enabled = False
    (or you could put btnPause.Visible + False to hide it completely)

    Then in the start Button click event (I called it Button4) put

    btnPause.Enabled = True (or .Visible = True)


    That means you will have to have a Stop button for which you will use similar Enabled code and in its click event include making itself and btnPause disabled etc.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  26. #26
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by private1337
    I can't set to count down mode when I modify to -1. It prompt me

    An unhandled exception has occured in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will be shut down immediately.

    Ticks must be between DatEime.MinValue.Ticks and
    Date.Time.MaxValue.Ticks.
    Parameter name: ticks

    when I Start the timer using the Start button. Any idea?
    The program WILL count backwards from a given time if you amend

    EndTime += 1

    to

    EndTime -= 1

    I suspect that you amended the Timer.Interval
    value to -1 But that should have given you a different error message. Check all of your code carefully with mine.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Hi, my timer seems to have something wrong. By the way, my timer will shown 00:00:00:00: if I reset it, any idea that how can I make off the last : away?

    And your time seems not run with seconds, it slows down and I saw it slow down like from 00:00:00:00 to 00:00:00:99 and actual run by seconds should be 00:00:00:00 to 00:00:00:60.
    The Power Of Sharing Knowledge!

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Originally posted by taxes
    Hi,

    To set a time as an alarm point you use a timer tick event to check Now.

    If the user is entering a time period, one way is when you want to start the period, to set a variable to Now.AddHours (or minutes or seconds as you wish); set the timer interval to the appropriate level and check for Now>= the variable.

    If the user is entering the actual alarm time then you simply use that entry for the variable value.

    Coding a stopwatch is more complicated and someone else may come up with an answer before I have worked it out.
    I not so understand what you mean by this, can u explained more further. I want to have a TextBox for people to input the time to ring and I would like to have the Snooze function codings etc... Wish you can explained more further. Thanks
    The Power Of Sharing Knowledge!

  29. #29
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by private1337
    Hi, my timer seems to have something wrong. By the way, my timer will shown 00:00:00:00: if I reset it, any idea that how can I make off the last : away?

    And your time seems not run with seconds, it slows down and I saw it slow down like from 00:00:00:00 to 00:00:00:99 and actual run by seconds should be 00:00:00:00 to 00:00:00:60.
    NO. My code is correct.. the right hand :00 represents hundredths of a second not 60 ths of anything.

    Sorry I had not noticed the final : amend the code as follows (Only relative code shown)

    VB Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         If bTimer = False Then
    3.             sTime = ""
    4.             EndTime -= 1 '            every 1000 th sec   increase by 1.
    5.             TimeLeft = EndTime + 0.001       'ensure value is rounded up
    6.             RunTime = Int(TimeLeft) / 100 / 60 / 60     'calculate hours
    7.             sTime = FormatRunTime(CStr(Int(RunTime))) & ":"
    8.             TimeLeft = (RunTime - Int(RunTime)) * 60 + 0.0001  'calculate minutes
    9.             sTime = FormatRunTime(CStr(Int(TimeLeft))) & ":"
    10.             TimeLeft = (TimeLeft - Int(TimeLeft)) * 60 + 0.0001  'calculates seconds
    11.             sTime = FormatRunTime(CStr(Int(TimeLeft))) & ":"
    12.             TimeLeft = (TimeLeft - Int(TimeLeft)) * 100 + 0.0001   'calculates 100 ths
    13.             sTime = FormatRunTime(CStr(Int(TimeLeft)))
    14.             TextBox3.Text = sTime
    15.         End If
    16.     End Sub
    17.     Private Function FormatRunTime(ByVal rt As String)
    18.         rt = Format(Val(rt), 0)
    19.         If Val(rt) < 1 Then
    20.             rt = "00"
    21.         ElseIf Val(rt) < 10 Then
    22.             rt = "0" & rt
    23.         End If
    24.         rt = sTime & rt
    25.         Return rt
    26.     End Function
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  30. #30
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    "I not so understand what you mean by this, can u explained more further. I want to have a TextBox for people to input the time to ring and I would like to have the Snooze function codings etc... Wish you can explained more further. Thanks "



    You really ought to be trying to write this code yourself and then post your attempts if you need help. You are asking me to write the entire code for you. I will work on this but will not post any more code until you make a reasonable attempt.
    Last edited by taxes; Nov 7th, 2004 at 10:22 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Sorry too. I have create another new clean form and check for my error. The last 00: is fixed. But the seconds still not accurate. I try to configure and I think the BOLD coding 100 should change to 60 to be accurate. Because I try clean my codings and a new form also got problem. So I try change to 60 and it seems work for me in seconds mode.

    If I change it, will it affect the program?

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If bTimer = False Then
    sTime = ""
    EndTime -= 1 ' every 1000 th sec increase by 1.
    TimeLeft = EndTime + 0.001 'ensure value is rounded up
    RunTime = Int(TimeLeft) / 100 / 60 / 60 'calculate hours
    sTime = FormatRunTime(CStr(Int(RunTime))) & ":"
    TimeLeft = (RunTime - Int(RunTime)) * 60 + 0.0001 'calculate minutes
    sTime = FormatRunTime(CStr(Int(TimeLeft))) & ":"
    TimeLeft = (TimeLeft - Int(TimeLeft)) * 60 + 0.0001 'calculates seconds
    sTime = FormatRunTime(CStr(Int(TimeLeft))) & ":"
    TimeLeft = (TimeLeft - Int(TimeLeft)) * 100 + 0.0001 'calculates 100 ths
    sTime = FormatRunTime(CStr(Int(TimeLeft)))
    TextBox3.Text = sTime
    End If
    End Sub
    The Power Of Sharing Knowledge!

  32. #32
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Why do you say the seconds are not accurate? I have cut and pasted your coding into my timer_tick event and it works perfectly. I have compared the seconds and minutes display the stopwatch function in my wristwatch and they are correct.

    The 100 ths display is far too fast for you to read (your eyes work at approximately one- twentyfifth of a second so even if your eyesight is very sharp you will only see every fourth character of the display).
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Oh.. Finally resoved the Timer Things. The Start Pause etc. button I will configure myself. Don't wish to trouble you much. But is it possible to make the countdown mode to let user enter specifc Days / Hours / Minutess / Seconds in the TextBox?

    I think this is gonna hard but I don't think TextBox is the suitable choice.. Any idea in mind??

    For the alarm thing, maybe I can explained in this way, the Alarm for my program will be like when the user set specifc time, it will play a specifc sound file and prompt a message box.

    Things that needed I think should be a Timer of course, TextBox for user to input time but I don't think its the best, A Browse Button for user to choose a list of wav sound file to play. And probaly a messagebox or a form in AlwaysOnTop mode.

    Always on Top coding anyone has it or understand it?
    The Power Of Sharing Knowledge!

  34. #34
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I would suggest using NumericUpDown boxes to accept a target time input as this will remove most possibilities of entry error. Use 3 boxes alongside each other, one for hours, one for minutes, one for seconds. (If you are also using days then you obviously need 4 boxes)

    For the Alarm sequence, you are obviously going to check for the display being <= 00:00:00:00:00, but you will have to be careful in how you do the comparison. It might be easier to check the value of each segment and set a boolean to indicate that segment reaching the relative number. e.g. Say the target time is 1 day, 5 hours, 10 minutes and 30 seconds, then as soon as the days have reached 00 set bdays to true. Then when the hours have reached 00, if bdays is true set the bHours to true etc.

    Search this forum for Always on Top as it has been raised before.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  35. #35

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Ya.. NumericUpDown is a great choice to choose. So it will be counting down on the NumericUpDown box or a new TextBox?

    For the Alarm things, 2nd Paragraph, I not really sure what your are saying, but I will try your method or other method..

    For the AlwaysOnTop, I can't find it in this forum. It all is in Classic Visual Basic. I need it for VB.Net... And can I have the Browse button coding?
    The Power Of Sharing Knowledge!

  36. #36
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by private1337
    Ya.. NumericUpDown is a great choice to choose. So it will be counting down on the NumericUpDown box or a new TextBox?

    For the Alarm things, 2nd Paragraph, I not really sure what your are saying, but I will try your method or other method..

    For the AlwaysOnTop, I can't find it in this forum. It all is in Classic Visual Basic. I need it for VB.Net... And can I have the Browse button coding?

    1. NumericUpDown is used simply to allow the user to set the time at which the alarm will sound. In this sense "Time" means the amount of days, hours, seconds, commencing now, on which the alarm will sound. So you still use a label (in preference to a textbox) to display the timer progress - the same one as you are using now.


    2. Note. You will need to experiment a lot, so you will learn a lot


    3. I will have a look at always on top.


    4. With regard to browsing through sound files, you can use either an openfiledialog box, a listbox, a listviewbox or a dropdown combobox, depending on the extent of your knowledge and the code for a browse button will be very short, just enough to make the relative box avtive. You will have to be prepared to do some homework on this.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  37. #37

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Thanks for your advice, I found browse button coding on

    http://www.vbforums.com/showthread.p...=browse+button

    It works great but I need to do some edit the coding though. But under the

    If trim(OFD.FileName) > "" Then
    'Do your upload stuff -> How can I set C:/ As Default Directory? I try OFD.InitialDirectory = ("C:/") but it can't work
    End If

    Waiting for your Always On Top commands and your help if needed... Thanks
    The Power Of Sharing Knowledge!

  38. #38
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    For always on top use Me.Topmost = True in the form_load event.

    Look up OpenFile Dialog in MSDN Help.

    openFileDialog1.InitialDirectory = "c:\"

    You have the slash going the wrong way
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  39. #39

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    123
    Thanks The both coding works..
    Last edited by private1337; Nov 21st, 2004 at 03:08 AM.
    The Power Of Sharing Knowledge!

  40. #40
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Re: need help on my timer program[ResolveD]

    I want a Process to start at a Spectific time based on the Computer clock.

    What should I Be Searching for? I Tried Timer, tried a Few Links and they all gotta do with what this Thread does.

    Example: do a Sub at 16:55:45.

    And if this Changes, I need to enter the Time in a inputbox and it must convert to Date I guess.

    Do I Compare now.tolongtimestring to Something ... Completly Lost
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

Page 1 of 2 12 LastLast

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