Scheduling for nth weekday of month.

Discuss RoboTask here
deesloop
Posts: 70
Joined: Wed Feb 25, 2009 3:44 am

Scheduling for nth weekday of month.

Post by deesloop »

We have ameeting every 2nd thursday of the month
However I need to send a remind out 10 days before that
What I thougt was a task that runs every monday and checks to see if now + 10 days = 2nd thursday of the month
If so then email saying the meeting is now + 10 days please make sure your report is ready.

I cant see anything that lets me handle the 2nd thursday of the month scenario.

Any ideas?

Thanks
Oleg
Site Admin
Posts: 3032
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Scheduling for nth weekday of month.

Post by Oleg »

It seems some BASIC script is needed for this
I'll try to write an example a bit later.
Oleg Yershov
deesloop
Posts: 70
Joined: Wed Feb 25, 2009 3:44 am

Re: Scheduling for nth weekday of month.

Post by deesloop »

Great.
One thing I thought of
April 2014 - The 2nd thursday is 10th so the message would need send Mon 31 Mar
May 2014 would need a reminder sent 28th April

So it's not jsut a case of saying
if now() + 10 = 2nd thursday of this month then ...
It's more a case of saying
if now now() + 10 = a second thursday then ....
deesloop
Posts: 70
Joined: Wed Feb 25, 2009 3:44 am

Re: Scheduling for nth weekday of month.

Post by deesloop »

I think this Vbscript works...

Function secthur(chkdate)
Dim dtmp
dtmp = DateSerial(Year(chkdate), Month(chkdate), 1)
Do While WeekDay(dtmp) <> vbThursday
dtmp = dtmp + 1
Loop
secthur = dtmp + 7
End Function

x = secthur(int(now()))
if x< int(now()) then x = secthur(DateSerial(Year(now()), Month(Now()+1), 1))
if int(now()+10) = x then msgbox("10 days time is second Thursday")
Oleg
Site Admin
Posts: 3032
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Scheduling for nth weekday of month.

Post by Oleg »

I modified your script a little bit and made the example of the task (see below)
You can define the day of week, the order of the day and delta
Of course you have to run this task every day. The task should check the current date and make some alert (email, etc) or do nothing.

Code: Select all

 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1416408852
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task115"
Hide=INTEGER|0
ID=INTEGER|1182597866
LogOnAsUser=INTEGER|1
Name=STRING|"check date"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//delta - num days before hot time"
Params=FOLDER

[Actions\Action1\Params]
comment=STRING|"delta - num days before hot time"

[Actions\Action10]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action10\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{result}"

[Actions\Action11]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Make your alert."""
Params=FOLDER

[Actions\Action11\Params]
icon=STRING|"0"
msg0=STRING|"Make your alert."
msg1=STRING|"Put your code with alert here."
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action12]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action13]
ActionID=STRING|"A_ROBOTASK_ALERT"
Enabled=INTEGER|-1
Name=STRING|"Show Notification"
Params=FOLDER

[Actions\Action13\Params]
defh=STRING|"1"
defw=STRING|"1"
duration=STRING|"5"
height=STRING|"76"
icon=STRING|"3"
kind=STRING|"0"
message=STRING|"No action is needed."
position=STRING|"3"
title=STRING|"No action"
width=STRING|"330"

[Actions\Action14]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""DELTA"" with value ""10"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"DELTA"
varvalue=STRING|"10"

[Actions\Action3]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//day of week for test (1=Sunday, 7=Saturday)"
Params=FOLDER

[Actions\Action3\Params]
comment=STRING|"day of week for test (1=Sunday, 7=Saturday)"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""WD"" with value ""3"""
Params=FOLDER

[Actions\Action4\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"WD"
varvalue=STRING|"3"

[Actions\Action5]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//position of day of week (1-st, 2-nd, 3-d, 4-th)"
Params=FOLDER

[Actions\Action5\Params]
comment=STRING|"position of day of week (1-st, 2-nd, 3-d, 4-th)"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""NUMDAY"" with value ""2"""
Params=FOLDER

[Actions\Action6\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"NUMDAY"
varvalue=STRING|"2"

[Actions\Action7]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//result of the test"
Params=FOLDER

[Actions\Action7\Params]
comment=STRING|"result of the test"

[Actions\Action8]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""RESULT"" with value ""False"""
Params=FOLDER

[Actions\Action8\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"RESULT"
varvalue=STRING|"False"

[Actions\Action9]
ActionID=STRING|"BASIC_SCRIPT"
Enabled=INTEGER|-1
Name=STRING|"Internal basic script"
Params=FOLDER

[Actions\Action9\Params]
line00000=STRING|"' chkdate - date for test"
line00001=STRING|"' numday - order of the day: 1-st, 2-nd, 3-d, 4-th"
line00002=STRING|"' wd - day of week Sunday =1, Saturday =7"
line00003=STRING|"Function secthur( chkdate, numday, wd )"
line00004=STRING|"	Dim dtmp"
line00005=STRING|"	dtmp = DateSerial( Year( chkdate ), Month( chkdate ), 1)"
line00006=STRING|"	Do While Weekday( dtmp ) <> wd"
line00007=STRING|"		dtmp = dtmp + 1"
line00008=STRING|"	Loop"
line00009=STRING|"	secthur = dtmp + 7 * ( numday -1 )"
line00010=STRING|"End Function"
line00012=STRING|"Sub Main"
line00013=STRING|"	Dim x As Date"
line00014=STRING|"	Dim delta As Long"
line00015=STRING|"	Dim wd As Long"
line00016=STRING|"	Dim num As Long"
line00018=STRING|"	delta = CInt( RoboTaskApp.ExpandText( ""{delta}""	))"
line00019=STRING|"	wd = CInt( RoboTaskApp.ExpandText( ""{wd}"" ))"
line00020=STRING|"	num = CInt( RoboTaskApp.ExpandText( ""{numday}"" ))"
line00021=STRING|"	'delta = 12"
line00022=STRING|"	'wd = 5"
line00023=STRING|"	'num = 2"
line00025=STRING|"	x = secthur( Date + delta, num, wd )"
line00027=STRING|"	'If Int(Date + 10) = x Then MsgBox(""10 days time is second Thursday"")"
line00028=STRING|"	If Int( Date + delta ) = x Then"
line00029=STRING|"		RoboTaskApp.SetUserVariable( ""result"" , ""true"")"
line00030=STRING|"	Else"
line00031=STRING|"		RoboTaskApp.SetUserVariable( ""result"" , ""false"")"
line00032=STRING|"	End If"
line00033=STRING|"End Sub"
linecount=STRING|"34"
source=STRING|"0"
Save the task into a file and use menu Task->Import to import the task into RoboTask
Of course you need Basic plugin for RoboTask. You can find it on Download Page
You can use this direct link: http://www.robotask.com/downloads/BasicForRoboTask.exe
Oleg Yershov
deesloop
Posts: 70
Joined: Wed Feb 25, 2009 3:44 am

Re: Scheduling for nth weekday of month.

Post by deesloop »

OK.
Isee what you're doing there.
I did howver jsut write the whole thing in VBS
Which works fine.
But then to get it schedule I added it as a task.

However I get an error with this line

nicbrd=formatdatetime(brddate,vblongdate)

Basically i want to generate an email with a decent date format - vblongdate
However the task is failing as below

E: 04/03/2014 10:09:54: Expecting an already dimensioned array. Line 17 Col 22 ""
The script works fine as a VBScript but fails i nthis task.

Thanks



Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
Comment=STRINGLIST
ContinueOnError=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task14"
Hide=INTEGER|0
ID=INTEGER|1879612449
LogOnAsUser=INTEGER|1
Name=STRING|"Monday email re board reports"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER

[Actions\Action1]
ActionID=STRING|"BASIC_SCRIPT"
Enabled=INTEGER|-1
Name=STRING|" Monday board meeting check and email"
Params=FOLDER

[Actions\Action1\Params]
line00001=STRING|"Function secthur(chkdate)"
line00002=STRING|"    Dim dtmp"
line00003=STRING|"    dtmp = DateSerial(Year(chkdate), Month(chkdate), 1)"
line00004=STRING|"    Do While Weekday(dtmp) <> vbThursday"
line00005=STRING|"        dtmp = dtmp + 1"
line00006=STRING|"    Loop"
line00007=STRING|"    secthur = dtmp + 7"
line00008=STRING|"End Function"
line00010=STRING|"Sub Main"
line00011=STRING|"Dim objShell"
line00012=STRING|"x = secthur(Int(Now()))"
line00013=STRING|"If x< Int(Now()) Then x = secthur(DateSerial(Year(Now()), Month(Now()+1), 1))"
line00014=STRING|"brddate=x"
line00015=STRING|"rptdate=brddate -6"
line00016=STRING|"nicbrd=formatdatetime(brddate,vblongdate)"
line00017=STRING|"nicrpt=formatdatetime(rptdate,vblongdate)"
line00018=STRING|"mon=DatePart(""m"",brddate)"
line00019=STRING|"If mon = 1 Then mun = ""January"""
line00020=STRING|"If mon = 2 Then mun = ""February"""
line00021=STRING|"If mon = 3 Then mun = ""March"""
line00022=STRING|"If mon = 4 Then mun = ""April"""
line00023=STRING|"If mon = 5 Then mun = ""May"""
line00024=STRING|"If mon = 6 Then mun = ""June"""
line00025=STRING|"If mon = 7 Then mun = ""July"""
line00026=STRING|"If mon = 8 Then mun = ""August"""
line00027=STRING|"If mon = 9 Then mun = ""September"""
line00028=STRING|"If mon = 10 Then mun = ""October"""
line00029=STRING|"If mon = 11 Then mun = ""November"""
line00030=STRING|"If mon = 12 Then mun = ""December"""
line00031=STRING|"Set objShell = WScript.CreateObject (""WScript.shell"")"
line00032=STRING|"If Int(Now()+10) = x Then"
line00033=STRING|"strcommand = ""c:\sendemail.exe -f kyoung@mydomain.com -t Mofriel@mydomain.com;rinnes@mydomain.com;jcorser@mydomain.com;bdalton@mydomain.com;bpaterson@mydomain.com;iroberson@mydomain.com;pcornet@mydomain.com;lnish@mydomain.com;dbaxter@mydomain.com -bcc dslupek@mydomain.com;kyoung@mydomain.com -s mailserver.mydomain.com -u """
line00034=STRING|"strcommand = strcommand &  mun & "" board report due -m """
line00035=STRING|"strcommand = strcommand & ""The next board meeting will be on "" & nicbrd & Chr(13) & Chr(13) & ""Please ensure your board report is with me by "" & nicrpt & Chr(13) & Chr(13) & ""Thank you."""
line00036=STRING|"objShell.Run (strCommand)"
line00037=STRING|"Else"
line00038=STRING|"strcommand = ""c:\sendemail.exe -f kyoung@mydomain.com -bcc dslupek@mydomain.com; kyoung@mydomain.com -s mailserver.mydomain.com -u """
line00039=STRING|"strcommand = strcommand &  mun & "" board report not due -m """
line00040=STRING|"strcommand = strcommand & ""The next board meeting will be on "" & nicbrd & Chr(13) & Chr(13) & ""No email reminders need sent out."""
line00041=STRING|"objShell.Run (strCommand)"
line00042=STRING|"End If"
line00044=STRING|"End Sub"
linecount=STRING|"45"
source=STRING|"0"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_GENERAL_SHEDULER"
Params=FOLDER
UnigueID=INTEGER|16446209

[Events\Event1\Params]
id=STRING|"EDW273U8"
periodicity=STRING|"1"
periodparameter=STRING|"0100000"
startdate=STRING|"41702"
time0=STRING|"37800000"
timecount=STRING|"1"

Oleg
Site Admin
Posts: 3032
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Scheduling for nth weekday of month.

Post by Oleg »

Built it basic doesn't have function formatdatetime
Look in Help file of BASIC (F1 in script editor)

You can do like this (see below)

Code: Select all

Sub Main
	Dim dt As Date

	dt = Now

	MsgBox( CStr( dt ) )

	MsgBox( MonthName ( Month ( dt ) ) + " " + CStr(Day(dt)) + "," + CStr(Year(dt)) )

End Sub
Oleg Yershov
deesloop
Posts: 70
Joined: Wed Feb 25, 2009 3:44 am

Re: Scheduling for nth weekday of month.

Post by deesloop »

OK, Iupdated script but now it doesn't like

Set objShell = WScript.CreateObject ("WScript.shell")

Also F1 for help in script editor give me this error...
Why can't I get Help from this program?
The Help for this program was created in Windows Help format, which was used in previous versions of Windows and it is not supported in Windows Vista.
For more information, see Windows Help program (WinHlp32.exe) is no longer included with Windows on the Microsoft support website.
Its a W2k8 machine
Oleg
Site Admin
Posts: 3032
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Scheduling for nth weekday of month.

Post by Oleg »

deesloop wrote: Also F1 for help in script editor give me this error...
Why can't I get Help from this program?
The Help for this program was created in Windows Help format, which was used in previous versions of Windows and it is not supported in Windows Vista.
For more information, see Windows Help program (WinHlp32.exe) is no longer included with Windows on the Microsoft support website.
Its a W2k8 machine
You can see the link on this page where you can get valid WinHlp32.exe for your OS.
Also you can see here: http://www.microsoft.com/en-us/download ... x?id=19771
Oleg Yershov
Oleg
Site Admin
Posts: 3032
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Scheduling for nth weekday of month.

Post by Oleg »

OK, Iupdated script but now it doesn't like

Set objShell = WScript.CreateObject ("WScript.shell")
use this:

Code: Select all

Sub Main
   Dim objShell As Object

   Set objShell = CreateObject ("WScript.shell")
   ......

End Sub
SAX basic is a little bit another dialect. It is similar to MS VB6
Oleg Yershov
Post Reply