Solved

Fire up a code at a given time!

Posted on 2004-08-09
10
213 Views
Last Modified: 2010-05-02
Dear Experts,

I am trying to fire up a code,  to remind the user to perform a task once every week, i.e. every friday at 12:00:00 pm then shoud do x,y,z by a message box or something.  The application itself can be running all the time as long as it does not use much resources.  I am using vb6  

ANy ideas experts?

Thankx

Munzi
0
Comment
Question by:munzi79
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11751008
Create a timer, set its interval for example to 60 seconds and then check the time & date in timer code...

Darko
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 11751205
Or you may use the task sheduler, available in Windows98+, which can start any prpgram in given time and period
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11751221
True, although the task scheduler is used when the application is not running (all the time)

Darko
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 11752248
Below is one way to do it.  If you want the app to minimize to the tray then take a look at one of my previous solutions here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20998214.html

Option Explicit

Private targetMonth As Integer
Private targetDay As Integer
Private targetYear As Integer
Private targetHour As Integer
Private targetMinute As Integer

Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 1000
   
    targetHour = 12
    targetMinute = 0
    setNextTargetDate
    Timer1.Enabled = True
End Sub

Private Sub setNextTargetDate()
    Dim target As Date
    Dim dayOfWeek As Integer
    Dim curHour As Integer
    Dim curMinute As Integer
           
    target = Now()
    dayOfWeek = Weekday(target)
    If dayOfWeek < 6 Or dayOfWeek = 7 Then ' if it's not Friday...
        ' calculate the date of the next Friday
        If dayOfWeek < 6 Then
            target = DateAdd("d", 6 - dayOfWeek, target)
        Else
            target = DateAdd("d", 6, target)
        End If
        ' set our target month, day and year
        targetMonth = Month(target)
        targetDay = Day(target)
        targetYear = Year(target)
    Else ' it's Friday
        ' is it before or after our target time?
        curHour = Hour(target)
        curMinute = Minute(target)
        If curMinute >= targetMinute And curHour >= targetHour Then
            ' target time has already passed
            ' calculate the date of the next weeks Friday
            target = DateAdd("d", 7, target)
        End If
        ' set our target month, day and year
        targetMonth = Month(target)
        targetDay = Day(target)
        targetYear = Year(target)
    End If
    Debug.Print "Next Target DateTime:"
    Debug.Print targetMonth & "/" & targetDay & "/" & targetYear
    Debug.Print targetHour & ":" & targetMinute
End Sub

Private Sub Timer1_Timer()
    Dim curDateTime As Date
    Dim curMonth As Integer
    Dim curDay As Integer
    Dim curYear As Integer
    Dim curHour As Integer
    Dim curMinute As Integer
   
    curDateTime = Now()
    curMonth = Month(curDateTime)
    curDay = Day(curDateTime)
    curYear = Year(curDateTime)
    curHour = Hour(curDateTime)
    curMinute = Minute(curDateTime)
   
    If curMonth = targetMonth And curDay = targetDay And curYear = targetYear Then
        If curMinute >= targetMinute And curHour >= targetHour Then
            Timer1.Enabled = False
       
            MsgBox "Display your message or call a subroutine here"
       
            setNextTargetDate
            Timer1.Enabled = True
        End If
    End If
End Sub
0
 
LVL 4

Expert Comment

by:cachedVB
ID: 11759170
or just

timer1_timer()
if hour(now)  = 0 and minute(now) = 0 and second(now) = 0 then
'put stuff here
end if
end sub
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11759425
I think you missed this part cachedVB...

>> remind the user to perform a task once every week

...but yes, there are certainly simpler ways of accomplishing the task than I have shown.

Idle_Mind
0
 

Author Comment

by:munzi79
ID: 11771160
Hi  Idle_Mind

Thank you for your solution, it worked exactly the way we wanted it.  Just one more question if that is ok, i am working on a project where i will need to open/play a vedio clip on a iPAQ/PDA, do you know which language is the best to use, i.e. Embeded VB 3 or will i hve to use VB.Net?

Thanks once again.

Regards,

Munzi
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11771495
You can make whatever you want with eVB3  :)))

Darko
0
 

Author Comment

by:munzi79
ID: 11771767
Hi Darko,

I am strugling to make progress.  I have just started to use eVB3.  How do i play a .avi movie in my apllication.  Say for example the user keys in the file name,e.g. myMedia.avi anf then presses a button to play that file on the window below.

Thanks

Munzi
0
 

Author Comment

by:munzi79
ID: 11808039
Darko mate,

can you help me with this question, i have set it up as a new tread.

Rgds

Munzi
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question