Get time event at a specific time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas

    Get time event at a specific time

    Hi!

    Is it possible to get a time event at a specific time, for instance
    eight a'clock? My program is running in the background and is
    minimized to the tray bar.

    If not, is there a smooth way to accomplish this in a different way?

    Best regards,
    Andreas Lundgren
  • Raoul Watson

    #2
    Re: Get time event at a specific time


    "Andreas" <d99alu@efd.lth .se> wrote in message
    news:f7cd4365.0 310022357.75ec4 f66@posting.goo gle.com...[color=blue]
    > Hi!
    >
    > Is it possible to get a time event at a specific time, for instance
    > eight a'clock? My program is running in the background and is
    > minimized to the tray bar.
    >
    > If not, is there a smooth way to accomplish this in a different way?
    >
    > Best regards,
    > Andreas Lundgren[/color]

    Just put a timer control on the form and set it to fire every second.

    Somewhere in the code you set your target:

    Dim Target As Date
    Target = "10/4/2003 8:00 PM"

    And in the timer code you check for this target:

    Private Sub Timer1_Timer()
    If Now => Target Then
    ' fire the event that you need to happen at the target time
    End If
    End Sub


    Comment

    • J French

      #3
      Re: Get time event at a specific time

      On Fri, 03 Oct 2003 08:57:08 GMT, "Raoul Watson"
      <WatsonR@Intell igenCIA.com> wrote:
      [color=blue]
      >
      >"Andreas" <d99alu@efd.lth .se> wrote in message
      >news:f7cd4365. 0310022357.75ec 4f66@posting.go ogle.com...[color=green]
      >> Hi!
      >>
      >> Is it possible to get a time event at a specific time, for instance
      >> eight a'clock? My program is running in the background and is
      >> minimized to the tray bar.
      >>
      >> If not, is there a smooth way to accomplish this in a different way?
      >>
      >> Best regards,
      >> Andreas Lundgren[/color]
      >
      >Just put a timer control on the form and set it to fire every second.
      >
      >Somewhere in the code you set your target:
      >
      >Dim Target As Date
      >Target = "10/4/2003 8:00 PM"[/color]
      Hmm, that could have rather different results in the UK to the same
      code in the USA

      Personally I would use DateSerial() and TimeSerial() to avoid such
      ambiguity[color=blue]
      >
      >And in the timer code you check for this target:
      >
      >Private Sub Timer1_Timer()
      > If Now => Target Then
      > ' fire the event that you need to happen at the target time
      > End If
      >End Sub
      >
      >[/color]

      Comment

      • CajunCoiler \(http://www.cajuncoiler.tk\)

        #4
        Re: Get time event at a specific time

        Probably the simplest way is to set a timer event (interval=1000) that
        checks the value of Time$

        ' Timer object: Name="tmrTimeTr ap" Interval=1000
        '
        Private Sub tmrTimeTrap_Tim er()
        If (Time$="08:00" or Time$="20:00") Then
        Print "Do this thing at 8 o'clock"
        End If
        End Sub
        [color=blue]
        > Is it possible to get a time event at a specific time, for instance
        > eight a'clock? My program is running in the background and is
        > minimized to the tray bar.[/color]


        Comment

        • Raoul Watson

          #5
          Re: Get time event at a specific time

          "J French" <erewhon@nowher e.com> wrote in message
          news:3f7d4032.8 394884@news.btc lick.com...[color=blue]
          > On Fri, 03 Oct 2003 08:57:08 GMT, "Raoul Watson"
          > <WatsonR@Intell igenCIA.com> wrote:
          >[color=green]
          > >
          > >"Andreas" <d99alu@efd.lth .se> wrote in message
          > >news:f7cd4365. 0310022357.75ec 4f66@posting.go ogle.com...[color=darkred]
          > >> Hi!
          > >>
          > >> Is it possible to get a time event at a specific time, for instance
          > >> eight a'clock? My program is running in the background and is
          > >> minimized to the tray bar.
          > >>
          > >> If not, is there a smooth way to accomplish this in a different way?
          > >>
          > >> Best regards,
          > >> Andreas Lundgren[/color]
          > >
          > >Just put a timer control on the form and set it to fire every second.
          > >
          > >Somewhere in the code you set your target:
          > >
          > >Dim Target As Date
          > >Target = "10/4/2003 8:00 PM"[/color]
          > Hmm, that could have rather different results in the UK to the same
          > code in the USA
          >
          > Personally I would use DateSerial() and TimeSerial() to avoid such
          > ambiguity[color=green]
          > >
          > >And in the timer code you check for this target:
          > >
          > >Private Sub Timer1_Timer()
          > > If Now => Target Then
          > > ' fire the event that you need to happen at the target time
          > > End If
          > >End Sub
          > >
          > >[/color][/color]

          You're absolutely right.
          I was merely saying you set a target to give a quick example of the timer
          code which is what the poster was looking for.


          Comment

          • J French

            #6
            Re: Get time event at a specific time

            On Fri, 03 Oct 2003 23:45:45 GMT, "Raoul Watson"
            <WatsonR@Intell igenCIA.com> wrote:

            <snip>[color=blue]
            >
            >You're absolutely right.
            >I was merely saying you set a target to give a quick example of the timer
            >code which is what the poster was looking for.
            >[/color]

            Sorry, I get nervous of Dates

            - the 'real' answer - compare with a target is exactly how I would do
            it

            Comment

            • Tony Vitonis

              #7
              Re: Get time event at a specific time

              Another possibility is to set the timer interval to the difference between
              8:00 and "now". In VB.NET, you could implement a function like this:

              Private Function IntervalTill(By Val d As DateTime) As Integer

              Dim TodayTickTime As DateTime = Today.Add(d.Sub tract(#12:00:00 AM#))
              Dim TomorrowTickTim e As DateTime = TodayTickTime.A ddHours(24)
              Dim Difference As TimeSpan

              If DateTime.op_Les sThan(Now, TodayTickTime) Then
              Difference = TodayTickTime.S ubtract(Now)
              Else
              Difference = TomorrowTickTim e.Subtract(Now)
              End If

              Return Difference.Tota lMilliseconds

              End Function

              Then you could set your timer interval like this:

              Timer1.Interval = IntervalTill(#8 :00:00 PM#)

              This will avoid the overhead of timer code executing once a second (and
              potentially 86,399 times without doing anything). Also, if the event needs
              to happen every day at the same time, the code in the timer's Tick event
              could do its thing and then reset its own interval as above.

              Hope this helps. =c)
              [color=blue]
              > CajunCoiler wrote:
              >
              > Probably the simplest way is to set a timer event (interval=1000) that
              > checks the value of Time$
              >
              > ' Timer object: Name="tmrTimeTr ap" Interval=1000
              > '
              > Private Sub tmrTimeTrap_Tim er()
              > If (Time$="08:00" or Time$="20:00") Then
              > Print "Do this thing at 8 o'clock"
              > End If
              > End Sub
              >[color=green]
              > > Is it possible to get a time event at a specific time, for instance
              > > eight a'clock? My program is running in the background and is
              > > minimized to the tray bar.[/color][/color]


              Comment

              • Andreas

                #8
                Re: Get time event at a specific time

                Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
                value with a mamimum value of 65535 ms, about one minute...

                I was thinking and hoping that there might be an API call or upgraded
                timer that could give me an event after a longer time, and by that,
                let me use a function like the one that Coiler described below.

                "1 to 65,535 Sets an interval (in milliseconds) that takes effect
                when a Timer control's Enabled property is set to True. For example, a
                value of 10,000 milliseconds equals 10 seconds. The maximum, 65,535
                milliseconds, is equivalent to just over 1 minute."



                "Tony Vitonis" <noone@nowhere. com> wrote in message news:<MvSdnbpzd sG4BhSiU-KYhw@comcast.co m>...[color=blue]
                > Another possibility is to set the timer interval to the difference between
                > 8:00 and "now". In VB.NET, you could implement a function like this:
                >
                > Private Function IntervalTill(By Val d As DateTime) As Integer
                >
                > Dim TodayTickTime As DateTime = Today.Add(d.Sub tract(#12:00:00 AM#))
                > Dim TomorrowTickTim e As DateTime = TodayTickTime.A ddHours(24)
                > Dim Difference As TimeSpan
                >
                > If DateTime.op_Les sThan(Now, TodayTickTime) Then
                > Difference = TodayTickTime.S ubtract(Now)
                > Else
                > Difference = TomorrowTickTim e.Subtract(Now)
                > End If
                >
                > Return Difference.Tota lMilliseconds
                >
                > End Function
                >
                > Then you could set your timer interval like this:
                >
                > Timer1.Interval = IntervalTill(#8 :00:00 PM#)
                >
                > This will avoid the overhead of timer code executing once a second (and
                > potentially 86,399 times without doing anything). Also, if the event needs
                > to happen every day at the same time, the code in the timer's Tick event
                > could do its thing and then reset its own interval as above.
                >
                > Hope this helps. =c)
                >[color=green]
                > > CajunCoiler wrote:
                > >
                > > Probably the simplest way is to set a timer event (interval=1000) that
                > > checks the value of Time$
                > >
                > > ' Timer object: Name="tmrTimeTr ap" Interval=1000
                > > '
                > > Private Sub tmrTimeTrap_Tim er()
                > > If (Time$="08:00" or Time$="20:00") Then
                > > Print "Do this thing at 8 o'clock"
                > > End If
                > > End Sub
                > >[color=darkred]
                > > > Is it possible to get a time event at a specific time, for instance
                > > > eight a'clock? My program is running in the background and is
                > > > minimized to the tray bar.[/color][/color][/color]

                Comment

                • J French

                  #9
                  Re: Get time event at a specific time

                  On 14 Oct 2003 02:32:09 -0700, d99alu@efd.lth. se (Andreas) wrote:
                  [color=blue]
                  >Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
                  >value with a mamimum value of 65535 ms, about one minute...
                  >
                  >I was thinking and hoping that there might be an API call or upgraded
                  >timer that could give me an event after a longer time, and by that,
                  >let me use a function like the one that Coiler described below.[/color]

                  I think you misunderstand what he was saying

                  As everyone suggested, set up a Timer that fires every second, and
                  checks whether the system time has reached a specified forward date.


                  Comment

                  • Steve Gerrard

                    #10
                    Re: Get time event at a specific time

                    This link is to an MSDN library article on using timers through the API. You can
                    set a timer up to 4 billion milliseconds ahead, which is about 49.7 days. Not
                    suprisingly, I haven't tested one set that long.



                    "Andreas" <d99alu@efd.lth .se> wrote in message
                    news:f7cd4365.0 310140132.27339 29f@posting.goo gle.com...[color=blue]
                    > Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
                    > value with a mamimum value of 65535 ms, about one minute...
                    >
                    > I was thinking and hoping that there might be an API call or upgraded
                    > timer that could give me an event after a longer time, and by that,
                    > let me use a function like the one that Coiler described below.
                    >
                    > "1 to 65,535 Sets an interval (in milliseconds) that takes effect
                    > when a Timer control's Enabled property is set to True. For example, a
                    > value of 10,000 milliseconds equals 10 seconds. The maximum, 65,535
                    > milliseconds, is equivalent to just over 1 minute."
                    >
                    >
                    >
                    > "Tony Vitonis" <noone@nowhere. com> wrote in message[/color]
                    news:<MvSdnbpzd sG4BhSiU-KYhw@comcast.co m>...[color=blue][color=green]
                    > > Another possibility is to set the timer interval to the difference between
                    > > 8:00 and "now". In VB.NET, you could implement a function like this:
                    > >
                    > > Private Function IntervalTill(By Val d As DateTime) As Integer
                    > >
                    > > Dim TodayTickTime As DateTime = Today.Add(d.Sub tract(#12:00:00 AM#))
                    > > Dim TomorrowTickTim e As DateTime = TodayTickTime.A ddHours(24)
                    > > Dim Difference As TimeSpan
                    > >
                    > > If DateTime.op_Les sThan(Now, TodayTickTime) Then
                    > > Difference = TodayTickTime.S ubtract(Now)
                    > > Else
                    > > Difference = TomorrowTickTim e.Subtract(Now)
                    > > End If
                    > >
                    > > Return Difference.Tota lMilliseconds
                    > >
                    > > End Function
                    > >
                    > > Then you could set your timer interval like this:
                    > >
                    > > Timer1.Interval = IntervalTill(#8 :00:00 PM#)
                    > >
                    > > This will avoid the overhead of timer code executing once a second (and
                    > > potentially 86,399 times without doing anything). Also, if the event needs
                    > > to happen every day at the same time, the code in the timer's Tick event
                    > > could do its thing and then reset its own interval as above.
                    > >
                    > > Hope this helps. =c)
                    > >[color=darkred]
                    > > > CajunCoiler wrote:
                    > > >
                    > > > Probably the simplest way is to set a timer event (interval=1000) that
                    > > > checks the value of Time$
                    > > >
                    > > > ' Timer object: Name="tmrTimeTr ap" Interval=1000
                    > > > '
                    > > > Private Sub tmrTimeTrap_Tim er()
                    > > > If (Time$="08:00" or Time$="20:00") Then
                    > > > Print "Do this thing at 8 o'clock"
                    > > > End If
                    > > > End Sub
                    > > >
                    > > > > Is it possible to get a time event at a specific time, for instance
                    > > > > eight a'clock? My program is running in the background and is
                    > > > > minimized to the tray bar.[/color][/color][/color]


                    Comment

                    • Andreas

                      #11
                      Re: Get time event at a specific time

                      Thanks!

                      This was what I wanted! As you can see, I'm don't like to following
                      standard MS coding standard, "Make the timer go of every second, and
                      if the computer gets slower, why not upgrade to a faster processor?".

                      "Steve Gerrard" <notstevegerrar d@comcast.net> wrote in message news:<nYidnYwGn uBgMxGiRVn-tA@comcast.com> ...[color=blue]
                      > This link is to an MSDN library article on using timers through the API. You can
                      > set a timer up to 4 billion milliseconds ahead, which is about 49.7 days. Not
                      > suprisingly, I haven't tested one set that long.
                      >
                      > http://support.microsoft.com/default...b;en-us;180736
                      >
                      > "Andreas" <d99alu@efd.lth .se> wrote in message
                      > news:f7cd4365.0 310140132.27339 29f@posting.goo gle.com...[color=green]
                      > > Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
                      > > value with a mamimum value of 65535 ms, about one minute...
                      > >
                      > > I was thinking and hoping that there might be an API call or upgraded
                      > > timer that could give me an event after a longer time, and by that,
                      > > let me use a function like the one that Coiler described below.
                      > >
                      > > "1 to 65,535 Sets an interval (in milliseconds) that takes effect
                      > > when a Timer control's Enabled property is set to True. For example, a
                      > > value of 10,000 milliseconds equals 10 seconds. The maximum, 65,535
                      > > milliseconds, is equivalent to just over 1 minute."[/color][/color]

                      Comment

                      Working...