Jump to content
Sign in to follow this  
jbennett

msgbox to popup on Monday or reminder on other days if doesn't pop up

Recommended Posts

jbennett

Hi everyone,

I've got a question regarding something i'm trying to create and really struggling to work out.

I'm trying to create some code that is scheduled to popup a msgbox on monday but will pop up a reminder msgbox on tuesday,wednesday,thursday or friday if the msgbox doesn't appear on monday due to the user not turning on their computer.

If the msgbox is popped up on Monday then it will not pop up during the rest of the week.

and if the msgbox pops up on any of the other days then it will not pop up again until the next monday.

Does anyone know how I can achieve this as it seems very complex to get working.

Thanks

Share this post


Link to post
Share on other sites
Bert

Look in the date management functions for examples.

_DateDayOfWeek should give you some direction. You could do something like this:

$sLongDayName = _DateDayOfWeek( @WDAY )
if $sLongDayName = "Monday" then msgbox(0, "", "message")
if $sLongDayName = "Tuesday" then msgbox(0, "", "reminder")

Share this post


Link to post
Share on other sites
jbennett

Thanks.

The problem with that code is that I can't see how this would work with the rest of the week.

I've currently created code that works with Monday and uses a .txt file that is created once the code has run, and then uses datediff to delete this file if older than 6 days,

hence it will run every week. The problem occurs with the other days.

I've tried to create a .txt file if run on Tuesday,wednesday,thursday and friday to prevet the reminder appearing more than once during the current week, but this causes many problems.

Edited by jbennett

Share this post


Link to post
Share on other sites
jbennett

Hi everyone,

I've made some progress but still not got an answer :-(

I've set the program to create a .txt file after a scheduled Monday backup is performed which expires after 6 days so that it will always run each Monday

For the other days I have used WeekNumberISO and put the current week number into an .ini file and I compare this with the week, therefore the next week if the msgbox is not displayed on the Monday it will remind the user again.

However a problem becomes obvious if a reminder is displayed one week and the next week as this then causes the reminder to become totally reliant on the week number in the .ini, which is not good if I change my scheduled data as it could run the reminder on a Wednesday, even though the actual schedule may be Thursday.

Can anyone make sense of this and offer me some advice?

Thanks

Edited by jbennett

Share this post


Link to post
Share on other sites
Valuater

Volly already showed you how

#Include <Date.au3>

Check_Date()

Func Check_Date()
    $sLongDayName = _DateDayOfWeek(@WDAY)
    If $sLongDayName <> "Saturday" And $sLongDayName <> "Sunday" Then
        ; do something?
        MsgBox(0, "Reminder", "Today is " & $sLongDayName)
    EndIf
EndFunc   ;==>Check_Date

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
jbennett

Thanks,

I understand the code but it becomes complicated if I use any other day than Monday because...

If the scheduled day is Wednesday and it's Thursday then the code will run a reminder, but the next Monday/Tuesday it will also run which is not required as it shouldn't run again until the scheduled day of Wednesday or the reminder days of Thursday/Friday/Saturday/Sunday/Monday/Tuesday if it's a reminder.

Maybe i'm getting myself confused?

I've currently got code that if it's a scheduled day then it will create a txt file with a 6 day expiry, therefore the scheduled msg will not appear again until 7 days, which is great

But if the 7 days pass then a reminder msg will appear and then confusion is obviously present in my code and things go a bit wrong.

Edited by jbennett

Share this post


Link to post
Share on other sites
jbennett

Haha I wish I could :mellow:

I'm finding it very hard to explain.

Scheduled day = runs once a week

Reminder days = runs once during each week if scheduled day is missed and then will not run again until the next scheduled day has passed.

Outcome 1 Therefore if scheduled day is Wednesday and it's missed then it should be possible for the code to remind the user up until the next Tuesday

Outcome 2 If Wednesday schedule is run then the reminder will not run unless the schedule on the next Wednesday is not run (This is pretty easy to code as all I need to know is that after 6 days it will run again)

Edited by jbennett

Share this post


Link to post
Share on other sites
jbennett

Hi everyone,

I've now got the code to work with the following

If the scheduled day is a monday and it runs on a Monday then it will put the weeknumber in my .ini file

Then it will check for this on Tuesday, Wednesday, Thursday and Friday and if it finds that the week number in the .ini is the same as the current week then the program will exit. If it's not the same as the week number in the .ini then it will run the code and put the week number in the .ini

The problem is when I set the schedule to something like a Thursday and run the code on a Friday because it will still run on the next Monday even though he schedule is a Thursday.

Does anyone know how I can get over this problem. Thanks

Edited by jbennett

Share this post


Link to post
Share on other sites
PsaltyDS

Hi everyone,

I've now got the code to work with the following

If the scheduled day is a monday and it runs on a Monday then it will put the weeknumber in my .ini file

Then it will check for this on Tuesday, Wednesday, Thursday and Friday and if it finds that the week number in the .ini is the same as the current week then the program will exit. If it's not the same as the week number in the .ini then it will run the code and put the week number in the .ini

The problem is when I set the schedule to something like a Thursday and run the code on a Friday because it will still run on the next Monday even though he schedule is a Thursday.

Does anyone know how I can get over this problem. Thanks

Sounds like all you need is @WDAY. If @WDAY is >= the day of the week you want the message to pop up, and _DateDiff() < 7, then show message. You can use _DateToDayOfWeek() to get the day of the week from the date.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
jbennett

Hey,

Do you have an example I could look at because I feel a bit confused.

Thanks :-)

Sounds like all you need is @WDAY. If @WDAY is >= the day of the week you want the message to pop up, and _DateDiff() < 7, then show message. You can use _DateToDayOfWeek() to get the day of the week from the date.

:mellow:

Share this post


Link to post
Share on other sites
PsaltyDS

Hey,

Do you have an example I could look at because I feel a bit confused.

Thanks :-)

You've been around here long enough to produce some code to talk about.

Write the date you want the message to come up to the ini file.

When the message is displayed, delete the entry. If you need to reschedule for the next week, just write a new entry with the next date.

Each time you check the ini file to see if there is a message pending, you can use _DateDiff() to see if it is too old to be presented now.

If _DateDiff("D", $sMsgDate, $sNowDate) > 7 (or however many days you like) then it's too old: delete or reset the entry in the ini file.

If that's a negative number then it's not the day for the message yet.

To check the day of the week compare @WDAY with _DateToDayOfWeek($sMsgDate) to set the conditions you want.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
jbennett

Hi,

I understand but i've already got that side of things to work.

My code runs once a week on the scheduled day as it checks if the last scheduled msgbox appeared more than 6 days ago and runs if this is the case.

The problem is with the reminders if the backup is not run on the scheduled day.

For instance if the scheduled day is a Wednesday and the user is reminded on a Thursday then I would not expect anything to happen again until the next Wednesday.

Thanks

Edited by jbennett

Share this post


Link to post
Share on other sites
PsaltyDS

Hi,

I understand but i've already got that side of things to work.

My code runs once a week on the scheduled day as it checks if the last scheduled msgbox appeared more than 6 days ago and runs if this is the case.

The problem is with the reminders if the backup is not run on the scheduled day.

For instance if the scheduled day is a Wednesday and the user is reminded on a Thursday then I would not expect anything to happen again until the next Wednesday.

Thanks

So this script only runs once a week? Then what is supposed to kick off the reminders? How many scripts are we talking about here?

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
jbennett

I will try and explain the best I can.

The script runs once a week as a schedule. Therefore if the scheduled day is Wednesday then it will run every Wednesday as long as the user turns on their PC.

If the user doesn't turn on their PC on Wednesday then it will remind them for the next 6 days that they didn't run the program on the schedued day, unless they accept the reminder on one of them days and then it will not remind them again.

Once it gets back to Wednesday it will start over again.

Sorry to be such a pain, it's just really making me feel quite sad at the moment as I just can't get my brain to operate properly.

Cheers

p.s. I should be able to schedule it for any day and it will do the same thing :-) Thats the plan.

EDIT

-----

I've tried to put it into words below.

This is the bit i've got working

Initial step
Compare file time of exists.txt and if it’s older than 6 days then delete

If scheduled day (e.g. Wednesday) then…
1 – check if msgbox already displayed by looking for exists.txt and exit if it exists
else
2 show msgbox
3 - Create exists.txt file

This is the bit that i'm stuck on

If reminder day (e.g. mon/tue/thurs/Friday) then…
This is where I get stuck.

I can only get it to work if i create another .txt file and then check if it's older than 6 days. But the problem with this
is that if the reminder is run on a Friday then even though the next reminder should be the next Thursday it will actually
not run until the Friday if that makes sense
Edited by jbennett

Share this post


Link to post
Share on other sites
PsaltyDS

I will try and explain the best I can.

The script runs once a week as a schedule. Therefore if the scheduled day is Wednesday then it will run every Wednesday as long as the user turns on their PC.

If the user doesn't turn on their PC on Wednesday then it will remind them for the next 6 days that they didn't run the program on the schedued day, unless they accept the reminder on one of them days and then it will not remind them again.

Once it gets back to Wednesday it will start over again.

Sorry to be such a pain, it's just really making me feel quite sad at the moment as I just can't get my brain to operate properly.

Cheers

p.s. I should be able to schedule it for any day and it will do the same thing :-) Thats the plan.

EDIT

-----

I've tried to put it into words below.

This is the bit i've got working

Initial step
Compare file time of exists.txt and if its older than 6 days then delete

If scheduled day (e.g. Wednesday) then
1  check if msgbox already displayed by looking for exists.txt and exit if it exists
else
2 show msgbox
3 - Create exists.txt file

This is the bit that i'm stuck on

If reminder day (e.g. mon/tue/thurs/Friday) then
This is where I get stuck.

I can only get it to work if i create another .txt file and then check if it's older than 6 days. But the problem with this
is that if the reminder is run on a Friday then even though the next reminder should be the next Thursday it will actually
not run until the Friday if that makes sense

OK, how about this:

Only one script scheduled to run every backup day AND in on every login (same script, via Run key or in Startup folder). A command line parameter can signal the usage: i.e. MyScript.exe /Backup launches the backup, or without the parameter it just checks for reminder. Use an .ini file to track the backup status.

When launched with the /Backup switch, a backup is performed and the date, time, and outcome of the backup, plus the date/time of the next backup goes into the .ini file.

When launched without the /Backup switch (by a logon) it checks the .ini file for last and next date/time and decides if a reminder is required.

What I don't see in your description above is any place to record the date/time of the last and next backups. It's because you seemed to only be thinking of a boolean FileExists() on your file, rather than having some useful data in there, that the logic gets broken. If your script can read the date/time of the last and next backup, then doing the logic for reminders becomes easy with functions that have already been pointed out to you, like _DateDiff().

If you want to get more geeky, the backup status info could all be in registry keys vice an .ini file.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
jbennett

Thanks that helps.

I have one question though..

How would I check if the Next backup has been missed.

I'm thinking something like the following

$next_backup = IniRead(@scriptdir & "\Configuration.ini", "BACKUP", "next_backup")
$currentday = something

If $nextbackup<$currentday Then 
MsgBox(4096, "Reminder", "Backup needs to be run", 0)

Share this post


Link to post
Share on other sites
jbennett

I've made an attempt with the knowledge I have of AutoIT and so far come up with the following:

#Include <Date.au3>


;====================================================================================
; $SCHEDULED MSGBOX
;====================================================================================
$Currentday = @WDAY
$scheduled_backup=IniRead(@scriptdir & "\test.ini", "BACKUP", "scheduled_backup","")
if $currentday=$scheduled_backup Then
    $msgbox = msgBox(4, "Scheduled", "It's a scheduled day", 0)

Iniwrite(@scriptdir & "\test.ini", "BACKUP", "next_scheduled_backup",$scheduled_backup)
endif

;====================================================================================
; REMINDER MSGBOX
;====================================================================================
$currentdate = @MDAY & @MON & @YEAR

$reminder_backup=IniRead(@scriptdir & "\test.ini", "BACKUP", "current_backup","")

$check_if_already_run = iniread(@scriptdir & "\test.ini", "BACKUP", "outcome", "")
if StringInStr($check_if_already_run, "YES") then
    Exit
else
    endif

MsgBox(4, "Scheduled Backup","The current day is  " & $currentdate, 0)
MsgBox(4, "Scheduled Backup","The backup was due on  " & $reminder_backup, 0)


if $currentdate>$reminder_backup Then
    $msgbox = msgBox(4, "Reminder", "You didn't run the backup, Run Now?", 0)

if $msgbox=7 Then
    Exit
Else
    endif
iniWrite(@scriptdir & "\test.ini", "BACKUP", "outcome","YES")
Iniread(@scriptdir & "\test.ini", "BACKUP", "current_backup",$reminder_backup)


endif
Edited by jbennett

Share this post


Link to post
Share on other sites
PsaltyDS

I've made an attempt with the knowledge I have of AutoIT and so far come up with the following:

You're getting closer! Check out this version. It backs up unconditionally when called with the "/backup" switch; otherwise it checks if the last successful backup was more than 7 days ago and prompts for it.

#include <Date.au3>

#cs
INI format:
-----------------
[BACKUP]
last_backup=2008/11/03 07:45:34
last_success=2008/11/03 08:07:21
last_outcome=success
#ce

; Check ini file
Global $sINI = @ScriptDir & "\test.ini"
If Not FileExists($sINI) Then
    MsgBox(16, "Error", "Required .ini file not found:  " & $sINI)
    Exit
EndIf
Global $sNow = _NowCalc()
Global $sLastBackup = IniRead($sINI, "BACKUP", "last_backup", "1970/01/01 00:00:00"); last attempt
Global $sLastOutcome = IniRead($sINI, "BACKUP", "last_outcome", ""); last outcome (success or fail)
Global $sLastSuccess = IniRead($sINI, "BACKUP", "last_success", "1970/01/01 00:00:00"); last successfull

; Check command line switch
Global $fBackup = ($CmdLine[0] > 0) And ($CmdLine[1] = "/backup")

If $fBackup Then
;=================================================================
; SCHEDULED Task
;   Triggered weekly by scheduled task or otherwise with /backup commandline switch
;=================================================================
    
    _RunBackup()
Else
;=================================================================
; REMINDER CHECK
;   Performed when /backup command line switch is not given
;=================================================================
    
    If _DateDiff("D", $sLastSuccess, $sNow) <= 7 Then
    ; Backups are up to date
        MsgBox(64, "Backups Current", "Backups are current." & @CRLF & _
                "Last successful backup was:  " & $sLastSuccess)
        Exit
    Else
    ; Last successful backup was more than a week ago
        If MsgBox(16 + 4, "Backup Required", "The last successful backup was more than a week ago:  " & @CRLF & _
                $sLastSuccess & @CRLF & @CRLF & _
                "Run backup now?") = 6 Then _RunBackup()
    EndIf
EndIf


Func _RunBackup()
; This is date/time of the attempt
    IniWrite($sINI, "BACKUP", "last_backup", _NowCalc())
    
; Backup process simulated here...
    If MsgBox(32 + 4, "Simulating backup", "Simulating backup... success?") = 6 Then
    ; assuming simulated backup succeeded...
        IniWrite($sINI, "BACKUP", "last_outcome", "success")
        IniWrite($sINI, "BACKUP", "last_success", _NowCalc())
    Else
    ; assuming simulated backup failed...
        IniWrite($sINI, "BACKUP", "last_outcome", "fail")
    EndIf
EndFunc

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
jbennett

Thanks

About to try it in a minute. Only problem is that line 62 seems to have an error.

Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×