Solved

Fire up a code at a given time!

Posted on 2004-08-09
10
211 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now