CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2001
    Posts
    23

    how to use Timer control to perform specific task at specific time of the day

    How can I use timer control if I want to send a file through email everyday at 9 am. here is the code I am trying to implement:
    Private Sub tmrSaleCode_Timer()
    'MyTime = TimeSerial(10, 19, 0)

    If Start1 = 0 Then
    Start1 = Timer
    End If
    Pause = 86400
    'Pause1 = 1000
    If Timer < Start1 Then
    Start1 = Timer
    End If
    If Timer > (Start1 + Pause1) Then
    'If MyTime = Time Then
    Start1 = Timer

    Module1.TestSndMail
    Label2.Caption = "Last Update = " & Now()
    'Else
    ' Start1 = Timer
    'End If
    End If

    End Sub
    Thanks.


  2. #2
    Join Date
    Apr 2001
    Location
    Salt Lake City, UT
    Posts
    135

    Re: how to use Timer control to perform specific task at specific time of the day

    I actually do it a little differently, but it is much easier to do (i think).
    1. on your form, add a text box and a timer control
    2. set the timer interval to 1000 (to update every second or 10000 to update every minute - whichever you prefer)
    3. add this event to the timer_timer() event :
    me.txtTime.text = format$(time(), "h:mm:ss AM/PM")
    where "txttime" is the name of the text box control
    4. add this event to the txtTime_Change() event:

    private Sub txtTime_Change()
    '//add triggered events here.
    Dim RunTime1 as string
    Dim TOD as string

    TOD = Right(me.txtTime.Text, 2)

    If TOD = "PM" then
    RunTime1 = Right(me.txtTime.Text, 10)
    ElseIf TOD = "AM" then
    RunTime1 = Right(me.txtTime.Text, 9)
    End If

    If RunTime1 = "9:00:00 AM" then
    MsgBox "It is now 9:00 AM. time to send out the reports!!", vbOKOnly, "Alarm"
    End If

    End Sub




    Let me know if you have any questions or need additional help.

    ~goddess
    [email protected]
    "There are no stupid questions, but there are a lot of inquisitive idiots."

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

Featured