• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

How to schedule a task using VB

I want to shedule a task using vb which will start an application at specific time (1pm, 3pm and 5pm) everyday (other than using windows task scheduler). Someone suggest using timer but would it give problem if i leave the timer running non-stop (i donno how to use timer also :P) ? is there a better way?
0
mr_avril
Asked:
mr_avril
1 Solution
 
jpaulinoCommented:
Is it in vb6 ?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you don't want to use the Task Scheduler...

Nothing wrong with having a Timer run all the time as long as you don't have the Interval set too high.

Add a Timer control to your form:

Option Explicit

Private Alarm1 As Date
Private Alarm2 As Date
Private Alarm3 As Date

Private Sub Form_Load()
    Alarm1 = DateAdd("h", 13, Date)
    If Now > Alarm1 Then
        Alarm1 = DateAdd("d", 1, Alarm1)
    End If
    Alarm2 = DateAdd("h", 15, Date)
    If Now > Alarm2 Then
        Alarm2 = DateAdd("d", 1, Alarm2)
    End If
    Alarm3 = DateAdd("h", 17, Date)
    If Now > Alarm3 Then
        Alarm3 = DateAdd("d", 1, Alarm3)
    End If
   
    ' check every second
    ' increase this if you like...if accuracy is less important
    ' for instance, check every 15 seconds (15000) instead
    Timer1.Interval = 1000
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    If Now > Alarm1 Then
        Alarm1 = DateAdd("d", 1, Alarm1)
       
        ' do something in here
        Shell "notepad", vbNormalFocus
       
    End If
    If Now > Alarm2 Then
        Alarm2 = DateAdd("d", 1, Alarm2)
       
        ' do something in here
        Shell "calc", vbNormalFocus
       
    End If
    If Now > Alarm3 Then
        Alarm3 = DateAdd("d", 1, Alarm3)
               
        ' do something in here
        Shell "mspaint", vbNormalFocus

    End If
End Sub
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now