Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Fire up a code at a given time!

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
munzi79
Asked:
munzi79
  • 3
  • 3
  • 2
  • +2
1 Solution
 
DarkoLordCommented:
Create a timer, set its interval for example to 60 seconds and then check the time & date in timer code...

Darko
0
 
tkalchevCommented:
Or you may use the task sheduler, available in Windows98+, which can start any prpgram in given time and period
0
 
DarkoLordCommented:
True, although the task scheduler is used when the application is not running (all the time)

Darko
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
cachedVBCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
munzi79Author Commented:
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
 
DarkoLordCommented:
You can make whatever you want with eVB3  :)))

Darko
0
 
munzi79Author Commented:
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
 
munzi79Author Commented:
Darko mate,

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

Rgds

Munzi
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now