Solved

Fire up a code at a given time!

Posted on 2004-08-09
10
212 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 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

13 Experts available now in Live!

Get 1:1 Help Now