Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Fire up a code at a given time!

Posted on 2004-08-09
10
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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 86

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

722 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